Support

Home Forums Event Espresso Premium Retrieving Ticket Quantity Using EE_Registration Class

Retrieving Ticket Quantity Using EE_Registration Class

Posted: August 24, 2023 at 12:35 am

Viewing 2 reply threads


edwardkay

August 24, 2023 at 12:35 am

In our current WordPress website project, we’ve created more than one ticket type (ex: member ticker and non-member ticket) for various events. Our users have the flexibility to purchase multiple quantities of these tickets. While working with the EE_Registration class to manage event registrations, I was able to retrieve essential information like ticket name and price using the $registration->ticket() method. However, I’m currently facing a challenge in obtaining the quantity of each category tickets that a user has purchased using this approach.

I’d greatly appreciate your assistance in finding a solution to retrieve the quantity of each ticket type purchased by a user through the EE_Registration class. Your support in this matter would be invaluable. Thank you!


Tony

  • Support Staff

August 24, 2023 at 2:20 pm

Hi there,

So registrations have a 1-to-1 relationship with tickets, each ticket will generate a registration so when you try to pull the qty for a specific registration, its 1.

But, from the EE_Registration you can get the related EE_Transaction, which links everything together ad holds the EE_Line_items (which is what you want for what I think you are trying to do).

Starting with a specific registration, if you have a registration and want to know how many of the related ticket were selected within that transaction you can do something like:

//Pull the related tkt line item:
$reg_tkt_line_item = $registration->ticket_line_item();

//Output the qty for that tkt line item:
echo $reg_tkt_line_item->quantity();

But, for what it sound like your doing, you need all of the ticket types from a specific transaction, so….

//Pull the EE_Transaction from the EE_Registration object.
$txn = $registration->transaction();

//Grab the line_items for actual 'purchased' items, like tickets
$tkt_line_items = $txn->items_purchased();

$tkt_line_items is now an array of line_items for each type of purchase within a transaction, loop over that and do whatever you need with those values.

Does that help?

Note, if you haven’t done so already I recommend taking a look over the model system docs:

https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System


edwardkay

August 25, 2023 at 12:38 am

I appreciate your assistance, Tony. The code you provided worked successfully for me.

Thanks


Rio

  • Support Staff

August 25, 2023 at 4:26 am

Awesome. If you need anything, feel free to reach us again.

thanks

Viewing 2 reply threads

The support post ‘Retrieving Ticket Quantity Using EE_Registration Class’ 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