Support

Home Forums Event Espresso Premium Attendee list – Show which ticket they bought

Attendee list – Show which ticket they bought

Posted: October 2, 2023 at 4:34 am


Michel van Schouten

October 2, 2023 at 4:34 am

Hi,

I’m looking for a way to customize my attendee list, which is visible on my site. I’ve managed to pull up some custom questions, however I want to list the exact ticket they’ve bought as well as this says something about their class they play in.

This is my .php:

<?php
/**
 * Content Template for the [ESPRESSO_EVENT_ATTENDEES] shortcode
 *
 * Please be sure to change the Question ID on line 19 to match your custom Question ID
 *
 * Template Args that are available in this template
 * @type EE_Attendee $contact
 * @type EE_Event   $event
 * @type bool       $show_gravatar  whether to show gravatar or not.
 */
$gender = '';
if( $contact instanceof EE_Attendee ) {
	$prev_answer_value = EEM_Answer::instance()->get_var( 
			array(
				array(
					'Registration.ATT_ID' => $contact->ID(),
					'Registration.EVT_ID' => $event->ID(),
					 'QST_ID' => 13, // gender
				),
				'order_by' => array(
					'ANS_ID' => 'DESC'
				),
				'limit' => 1
			),
			'ANS_value' );
	if( $prev_answer_value ) {
		$gender = ' — ' . $prev_answer_value;
	}
}	

$country = '';
if( $contact instanceof EE_Attendee ) {
	$prev_answer_value = EEM_Answer::instance()->get_var( 
			array(
				array(
					'Registration.ATT_ID' => $contact->ID(),
					'Registration.EVT_ID' => $event->ID(),
					 'QST_ID' => 14, // country
				),
				'order_by' => array(
					'ANS_ID' => 'DESC'
				),
				'limit' => 1
			),
			'ANS_value' );
	if( $prev_answer_value ) {
		$country = ' — ' . $prev_answer_value;
	}
}

?>
<?php do_action( 'AHEE__content-espresso_event_attendees__before', $contact, $show_gravatar ); ?>
<li><?php echo $contact->full_name() . $country . $gender; ?></li>
<?php do_action( 'AHEE__content-espresso_event_attendees__after', $contact, $show_gravatar ); ?>


Michel van Schouten

October 2, 2023 at 4:37 am

Sorry, forgot to add some text. So I’m looking for a way to display the name of their ticket as well. I’ve read a lot online, it seems like it doesn’t pull this information from contact but probably from registration. I’ve tried $ticket->TKT_name(), $TKT_name and $ticket_name, but none of them seem to be working.


Tony

  • Support Staff

October 3, 2023 at 6:19 am

Hi there,

[ESPRESSO_EVENT_ATTENDEES] pulls in the ‘Contacts’ for the registrations related to the event/datetime/ticket you pass to the shortcode.

You can think of EE_Contacts entities as ‘people’, an EE_Contact holds the First Name, Last Name, Email (and other details) that identify a person so it may help to think of the EE_Contact as the actual Attendee themselves.

EE_Contacts have a one-to-many relationship to EE_Registrations meaning a single person (let’s say me, Tony Warwick) can have multiple registrations assigned to it (because I can register multiple tickets, be it on the same or separate events). That means that what you are trying to do can get a little tricky because not all contacts will always have just one registration related to them, within the code you can always use the ‘latest’ registration for an event, but that design choice for that code (technically thats also what your answer code above is doing as its ordered by ANS_ID, meaning it will pull in the ‘latest’ answer to that question).

To pull in the latest registration for a specific event, you can use:

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

From there you can pull in the related ticket:

$ticket = $registration->ticket();

And output any details you want relating to the ticket from there, for example, ticket name:

$ticket->name()

Is that what you are looking for?

The support post ‘Attendee list – Show which ticket they bought’ 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