Last active
March 30, 2022 10:38
-
-
Save joshfeck/941ff81380f16e948245f8e0e6c985b6 to your computer and use it in GitHub Desktop.
Add a new capability to WP User account after they complete a registration for a specific event. Event Espresso 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file | |
add_action( | |
'AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment', | |
'my_add_user_cap_for_event', | |
10, | |
2 | |
); | |
function my_add_user_cap_for_event( | |
$transaction, | |
$update_params | |
) { | |
if($transaction->status_ID() != 'TCM') { | |
return; | |
} | |
$registrations = $transaction->registrations(); | |
foreach($registrations as $registration) { | |
if($registration instanceof EE_Registration) { | |
if($registration->get('EVT_ID') == 190) { // swap in your event ID here | |
$user = new WP_User(get_current_user_id()); | |
if( $user instanceof WP_User ) { | |
$user->add_cap('a_new_wp_capability'); // swap in your capability here | |
} | |
return; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment