Support

Home Forums Event Espresso Premium How do I get the data for multiple registrants

How do I get the data for multiple registrants

Posted: March 29, 2023 at 11:11 am

Viewing 1 reply thread


mbeede@tracom.com

March 29, 2023 at 11:11 am

Greetings – I have some back-end PHP code that I use to get several of the EE objects after registration submit:

// We need to get a few objects from Event Espresso
$checkout = EE_Registry::instance()->SSN->checkout();
if ( $checkout instanceof EE_Checkout )
{
$transaction = $checkout->transaction;
if ( $transaction instanceof EE_Transaction )
{
foreach ( $transaction->registrations() as $registration )
{
if ( $registration instanceof EE_Registration )
{
$attendee = $registration->attendee();
$event = $registration->event();
$ticket = $registration->ticket();
break; // That’s it
}
}
}
}

If there is just one registrant I can get at the attendee data like this:

// Required data needed for the MAX web services call
$addRegistrantArray = array();
$addRegistrantArray[‘learnerFirstName’] = $attendee->fname();
$addRegistrantArray[‘learnerLastName’] = $attendee->lname();
$addRegistrantArray[‘learnerEmail’] = $attendee->email();

BUT I am not sure how to get at the data if there are multiple registrants. I thought that the $attendee object would be an array of EE_Attendee objects, but that doesn’t seem to be the case.

Can you point me to some code, or show me some code on how to get at the attendee data for multiple registrants?

Thanks in advance – Mark


Tony

  • Support Staff

March 30, 2023 at 4:44 am

Hi Mark,

You’re already getting the info for all registrants with this:

foreach ( $transaction->registrations() as $registration ) {

$transaction->registrations() will return an array of EE_Registration objects and the foreach is looping over them all, however… because you have break; // That’s it you are breaking out of the foreach after a single iteration.

Remove the break and you’ll loop over each registration.

You then do something with each registration object within the loop:

foreach ( $transaction->registrations() as $registration )
{
    if ( $registration instanceof EE_Registration )
    {
        $attendee = $registration->attendee();
        $event = $registration->event();
        $ticket = $registration->ticket();
        // Do something with each registration here.
        // You have each individual EE_Attendee, EE_Event, EE_Ticket and EE_Regitration at this point.
    }
}
Viewing 1 reply thread

The support post ‘How do I get the data for multiple registrants’ 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