Support

Home Forums Event Espresso Premium Hiding ticket selector after registration

Hiding ticket selector after registration

Posted: December 7, 2018 at 1:23 pm


sogtalks@gmail.com

December 7, 2018 at 1:23 pm

We have built upon a solution EE has provided for dealing with ticket selector(s) still available after a successful registration but are still having one issue:

  • Using WP Users plugin
  • “Member” ticket only
  • One ticket only per logged-in user, ever.

I needed to hide the “Member” ticket row/selector upon registration. Using the code from https://gist.github.com/Pebblo/10669adfeea322ade3d96a38857fb46b I can display a message as required (Thank you for that) and can successfully remove the row BUT it removes the same Member ticket row from other events that the user has not yet registered for. I don’t want to use the Capability method as it doesn’t account for cancelled registrations.

Ideally I would like to specify the ticket for the event (it only specifies a registration I think) and only for a specific event.

Can you guide me please? Thank you.

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/ <strong>My Account</strong> page. Please contact mailto:xxx@xxx.com <strong>XXX XXXX</strong> if you wish to cancel your registration.</p>';

              // hide the Member ticket row
              echo '<style type="text/css">.ee-ticket-member{display:none;}</style>';
              
              remove_filter(
                    'the_content',
                    array('EED_Event_Single', 'event_tickets'),
                    EED_Event_Single::EVENT_TICKETS_PRIORITY,
                    1
                );

              
            }     
        }
    }
}


Josh

  • Support Staff

December 7, 2018 at 1:43 pm

One option would be to set a custom, one-time use capability (which can work with cancellations). You’ll find example code here:

https://gist.github.com/joshfeck/51c2ef122616b48cc4846b1f44384859

Another option would be to put together a custom script like this other user did:

https://eventespresso.com/topic/unique-emails-upon-registration/


sogtalks@gmail.com

December 12, 2018 at 4:13 pm

Those options won’t work for us. There is a series of four events per year, same basic tickets, Member and Guest.

I have been trying https://gist.github.com/Pebblo/10669adfeea322ade3d96a38857fb46b and it works to display the message but it displays on all events whether a ticket has been registered or not. In a perfect world I would be able to target a ticket with a specific name and at a specific event.


Josh

  • Support Staff

December 12, 2018 at 5:10 pm

These 2 lines of code:

$registration = $contact->get_most_recent_registration_for_event($post->ID);
if( $registration instanceof EE_Registration ) {

would normally make it so the message displays only on events where the logged in user has already registered, and not displayed on other events where they have not already registered.

I don’t have any guesses for why that message is appearing on all of your events. One possible troubleshooting step you could do would be to add:

echo 'Post ID is ' . $post->ID;
just before the line that starts with:
$registration = $contact->get_most_recent_registration_for_event($post->ID);

and, while logged into the site, check and make sure the Post ID printed on the screen matches the ID of the event.


sogtalks@gmail.com

December 13, 2018 at 8:15 pm

It seems the issue is with Trashed registrations, they still viewed as registrations.

  • Register for event with member ticket
  • Latest code adds message and hides ticket selector for specific event
  • admin Trashes registration, no longer on lists, but message remains and no ticket selector

Is there any way to be more specific regarding the status of a registration? And can I target a specific ticket name “Member” leaving Guest option still available?

Thank you.

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><span style="color:red">You have already registered for this event as a </span><strong> Member</strong></p>'; 

              // hide the Member ticket row
              echo '<style>.ee-ticket-member .ticket-selector-tbl-qty-slct{display:none;}</style>';
                
              remove_filter(
                'the_content',
                array('EED_Event_Single', 'event_tickets'),
                EED_Event_Single::EVENT_TICKETS_PRIORITY,
                1
              );
            }    
        }
    }
}


Tony

  • Support Staff

December 14, 2018 at 7:31 am

Hi there,

Is there any way to be more specific regarding the status of a registration?

Yes, there is, but you can’t use the method currently in use to do it.

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

With this:

$registration = $contact->get_first_related(
	'Registration',
	array(
		array(
			'EVT_ID' => $post->ID,
			'REG_deleted' => false
		), 
		'order_by' => array('REG_date' => 'DESC')
		)
);

That will not pull in registrations that have been trashed.

And can I target a specific ticket name “Member” leaving Guest option still available?

Yes, but you’ll need to use a completely different function and do it a little differently.

I’m assuming your ‘member’ ticket has a capability set on it?


sogtalks@gmail.com

December 14, 2018 at 9:12 am

Great, thanks for the Trash solution.

I’m assuming your ‘member’ ticket has a capability set on it?

Yes, but all events with have this specific Member ticket and have the same capability.


Tony

  • Support Staff

December 18, 2018 at 4:53 am

So depending on what you want to do, you can use something like this:

https://gist.github.com/Pebblo/eabb317ca126f5b298eca78755f2cbd1

That function works differently from the above in that it filters each row of the ticket selector, so the above pulls the capability set on the ticket (to make sure it only works on tickets with a cap set) and if one is set it will check if the current user’s contact has a registration for that ticket.

If it does it completely removes that ticket from the ticket selector, otherwise, it will show as normal.

There’s various different ways to handle that situation, for example you could output a message on the ticket selector similar to how the WP User integration add-on does now but the above should help get your started.

The support post ‘Hiding ticket selector after registration’ 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