Support

Home Forums Event Espresso Premium How to hide the Register Now button for those already registered Reply To: How to hide the Register Now button for those already registered

Reply To: How to hide the Register Now button for those already registered

Author Replies
Tony # Posted on May 15, 2018 at 4:12 am

Hi there,

There’s a couple of changes I would recommend making to that snippet (although it should work just fine as is) as we now have some methods built into EE that will reduce the workload needed for this.

$events = $contact->get_many_related( 'Event' );
// build an array of event IDs
foreach ( $events as $event ){
    $user_event_ids[] = $event->get( 'EVT_ID' );
}

That’s fairly inefficient for what you are trying to do, it pulls all events related to the contact, loops over them all to pull the ID’s and builds an array of ID that is used later to search through.

You only need to know if the user has just one registration on that event, right? So you can do something like this:

$registration = $contact->get_most_recent_registration_for_event($post->ID);

Pull the most recent registration for the current post (which in this case will be an event), if that function returns an EE_Regisitration object then the user has at least one registration on the event, meaning you can do:

if( $registration instanceof EE_Registration ) {
    //Output some text here and remove the ticket selector.
}

Try something like this:

https://gist.github.com/Pebblo/10669adfeea322ade3d96a38857fb46b

Which should also cover cases where you also display the ticket selector on the event list itself and not just the single event page. It removes the action used to add the ticket selector from the post rather than hiding the tickets after they have been added, which is what the additional code at the bottom is for.

As mentioned, Josh’s code will work fine as is with your changes, the above just uses some newer methods to pull the data easier so its up to you which one you prefer to use 🙂

Do NOT follow this link or you will be banned from the site!