An example of how to display a message and remove the ticket selector if the user has already registered onto the event before. The WP User Integration add-on is REQUIRED for this to work.
<?php //Please do not include the opening PHP tag if you already have one. | |
add_action( | |
'AHEE_event_details_before_the_content', | |
'my_add_content_event_if_logged_in_registered', | |
11 | |
); | |
function my_add_content_event_if_logged_in_registered( $post ) { | |
if ( is_user_logged_in() ) { | |
$user = wp_get_current_user(); | |
if ( ! $user instanceof WP_User ) { | |
return; | |
} | |
//is there an attached EE_Attendee? | |
$att_id = get_user_option( 'EE_Attendee_ID', $user->ID ); | |
if ( empty( $att_id ) ) { | |
return; //bail, no attached attendee_id. | |
} | |
//grab contact | |
$contact = EEM_Attendee::instance()->get_one_by_ID( $att_id ); | |
//if no contact then bail | |
if ( ! $contact instanceof EE_Attendee ) { | |
return; | |
} | |
// does the user have a registration for this event | |
$registration = $contact->get_most_recent_registration_for_event($post->ID); | |
if( $registration instanceof EE_Registration ) { | |
echo '<p style="color:red">You have already registered for this event, and your current registration status is ' . $registration->pretty_status() . '. If you need to request any changes to your registration, please contact the course administrator.</p>'; | |
if( is_single() ) { | |
remove_filter( | |
'the_content', | |
array('EED_Event_Single', 'event_tickets'), | |
EED_Event_Single::EVENT_TICKETS_PRIORITY, | |
1 | |
); | |
} elseif ( is_archive('espresso_events') ) { | |
remove_filter( | |
'the_content', | |
array('EED_Events_Archive', 'event_tickets'), | |
EED_Events_Archive::EVENT_TICKETS_PRIORITY | |
); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment