Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Forked from joshfeck/add_user_cap.php
Created March 30, 2022 10:38
Show Gist options
  • Save Pebblo/ccb58ca8b466b7a37bd39184ece1ab55 to your computer and use it in GitHub Desktop.
Save Pebblo/ccb58ca8b466b7a37bd39184ece1ab55 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
<?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_ticket',
10,
2
);
function my_add_user_cap_for_ticket(
$transaction,
$update_params
) {
if($transaction->status_ID() != 'TCM') {
return;
}
$registrations = $transaction->registrations();
foreach($registrations as $registration) {
if($registration instanceof EE_Registration) {
$TKT_ID = $registration->get('TKT_ID');
if($TKT_ID == 166) { // swap in your ticket ID here - This is for Early Bird Regular Membership
$user = wp_get_current_user();
if( $user instanceof WP_User ) {
write_log('add cap here');
$user->add_cap('foo'); // swap in your capability here
}
return;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment