Support

Home Forums Event Espresso Premium How to create a WP User Capability when user purchase a specific ticket?

How to create a WP User Capability when user purchase a specific ticket?

Posted: October 4, 2019 at 8:32 am


katorination

October 4, 2019 at 8:32 am

I would like to enable assign a WP User Capability to my WP users when they buy a ticket from a specific event. I have it set up that if they have to register to buy the ticket, then the Capability is set (all purchases must be via a logged-in registered user), however, this does not work for my returning users. Is there a way for me to do this?

My system:

*redacted*

Thanks!

  • This topic was modified 1 week, 5 days ago by  Josh. Reason: removed irrelevant information


Josh

  • Support Staff

October 4, 2019 at 12:12 pm

Hi,

Yes there is and it involves adding a bit of custom code into a custom functions plugin.

I shared a gist on GitHub as an example:

https://gist.github.com/joshfeck/941ff81380f16e948245f8e0e6c985b6

You can modify and add the above to a functions plugin.


Omar Paloma

October 7, 2019 at 2:29 am

That’s AWESOME!!!!!

Stumble across this by accident but 100% will use it!


Tony

  • Support Staff

October 7, 2019 at 5:34 am

Just to note, you may want to add a WP_User instance check to the above, if at some point you run an event that does not require the user to be logged in you’ll get a fatal error as add_cap() will not be available.

So this line:

$user->add_cap('a_new_wp_capability');

Would be:

if( $user instanceof WP_User ) {
    $user->add_cap('a_new_wp_capability');
}


katorination

October 7, 2019 at 7:35 am

Many thanks. I was just able to test this, and it worked like a charm.

You must be logged in to reply to this support post. Sign In or Register for an Account

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: publish

Updated by  katorination 1 week, 2 days ago ago

Topic Tags

Tagged: 

Notifications

This topic is:
pending
Do NOT follow this link or you will be banned from the site!