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 4 years, 6 months 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.

The support post ‘How to create a WP User Capability when user purchase a specific ticket?’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso