Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Created February 22, 2017 19:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshfeck/f73483e9df1f5ccc55f15a43fcecf463 to your computer and use it in GitHub Desktop.
Save joshfeck/f73483e9df1f5ccc55f15a43fcecf463 to your computer and use it in GitHub Desktop.
Check to see if the logged in member has registered for this event, then display a message on the single event page. Requires Event Espresso 4 + the WP User Integration add-on.
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
add_action(
'AHEE_event_details_before_post',
'my_add_content_event_if_logged_in_registered',
11
);
function my_add_content_event_if_logged_in_registered( $post ) {
if ( is_user_logged_in() && is_singular() ) {
$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;
}
// get events for this user
$events = $contact->get_many_related( 'Event' );
// build an array of event IDs
foreach ( $events as $event ){
$user_event_ids[] = $event->get( 'EVT_ID' );
}
// get this event's ID
$this_event_id = $post->ID;
// look for a match
if( in_array( $this_event_id, $user_event_ids ) ) {
echo '<h3>You\'ve been here before!</h3>';
} else {
echo '<h3>Welcome ' . $user->user_nicename . ', please register.</h3>';
}
}
}
@elvarcro
Copy link

elvarcro commented Jan 9, 2019

Where to add this code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment