Support

Home Forums Event Espresso Premium One ticket per user per event, does not work with multiple dates on 1 event

One ticket per user per event, does not work with multiple dates on 1 event

Posted: May 28, 2021 at 12:32 pm

Viewing 7 reply threads


joost backaert

May 28, 2021 at 12:32 pm

Hi, I’m using the code below to hide the subscribe button and ad some text when a person is already subscribed. This works fine with an event with one date but does not work if an event has multiple dates. Is this possible?


add_action(
'AHEE_event_details_after_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 ) {

if( is_single() ) {
echo '<p style="color:#ff533d">You have registered for this event. View your registration details on your membership-levels/membership-account/ My Account page. Please contact mailto:xxx@xxx.com XXX XXXX if you wish to cancel your registration.</p>';

// hide the Member ticket row
echo '<style type="text/css">.event-tickets{display:none;}</style>';

remove_filter(
'the_content',
array('EED_Event_Single', 'event_tickets'),
EED_Event_Single::EVENT_TICKETS_PRIORITY,
1
);

}
}
}
}


Tony

  • Support Staff

May 28, 2021 at 2:56 pm

Hi there,

I’m not sure why multiple dates would cause different behaviour with that code, can you explain further what happens?

The code above doesn’t use datetimes on the event, it basically just pulls the most recent registration made on an event which you pass as an ID. If any registrations are returned then you must have at least one registration on that event so it removes the ticket selector.


joost backaert

May 29, 2021 at 9:56 am

If I make an event and I make it with 2 dates and 2 different tickets for each date it is not possible to subscribe to the second date if the client should wish ( with the above code off course )


Tony

  • Support Staff

June 1, 2021 at 3:58 am

Oh, I understand now.

That’s not possible with that snippet, you could check for the number of datetimes on the event and if it’s greater than 1 quick out of that snippet to continue as EE normally would showing the ticket selector with all tickets.

Would that work?


joost backaert

June 1, 2021 at 10:57 am

That would work I think, is this thiket usable for that or what should I look at?

thanks


Tony

  • Support Staff

June 1, 2021 at 1:57 pm

Something like this:

$event = EEH_Event_View::get_event();
if( $event instanceof EE_Event ) {
    $datetimes = $event->datetimes();
    if(count($datetimes) > 1 ) {
        //Get out as this event has multiple datetimes.
        return;
    }
}

Should work, anywhere above the is_single() check should be fine.


joost backaert

June 2, 2021 at 1:53 pm

Hey Tony , you forgot a ) behind 1 but besides that it’s not really going to work, the plan was that a person could subscribe an extra date should he have forgotten but with this code he just can subscribe multiple times each event with more than one date ( this does not check how many different tickets there are) I don’t this will be possible without extensive coding i quess?


joost backaert

June 2, 2021 at 4:43 pm

Another question on the same snippet, if the registrant had a uzgent.be or a ugent.be email the registration is set to RAP end delivery notification is send, but when I use an event with the possibility to add more than one ticket it only approves the first one ( see for example https://itcit.be/opleidingen/test-opleiding-2-2/ )

Viewing 7 reply threads

The support post ‘One ticket per user per event, does not work with multiple dates on 1 event’ 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