Posted: November 28, 2017 at 5:40 pm
I’m attempting to place a limit on the number of tickets per event a unique user can purchase. Currently EE’s Ticket Limit feature works on a per transaction basis, allowing users to return to the page after ordering and simply order more discounted tickets. So far to record how many tickets a user has purchased I’ve written
However as you can see when I do a var_dump on $transaction I can’t find the number of tickets being purchased. Also what would be the best action hook to use for this? |
|
Hi there, Whilst I understand what you are trying to do, the code you’ve posted won’t work if you are using Mutli Event Registration (MER for short) and you add more events to the cart.
Loops over all of the registrations and sets If you’re not using MER then your looping over all of your registrations and pulling the same event each time, not a big deal but pretty inefficient. Assuming you’re not using MER I’d just pull the primary registrant from the transaction:
Check you have an instance of EE_Registration and pull the event from that.
If for some reason you don’t have a EE_Registration object all of your code will continue to run (and fail) because it is outside of that check, move that into the instance of check. If all you need is the event ID and the number of tickets purchased for that specific event (not the qty of each specific ticket type) then you can pull that from the EE_Registration object using group_size(), so you could have something like this:
Can I ask why you’re not using user meta to store this? If your using MER it gets more complicated, you’ll need to loop over each registration and pull its event, add that to an array and then set how many tickets for each event you have within an array on the event element, menaing your using a multidimensional array. After looping over all registration, assigning all ticket qty’s to each event you then loop over the array you created and add save the details.
It all depends on when you want to record the tickets, as soon as the user selects the tickets and adds registration details? When the registrations are paid/approved? You would be better opening up an issue, labeling it a question and providing more details on how/when you want this to work. One of our developers may be able to point you in the right direction from there. Note – we do not provide support for custom code, whilst we are usually more than happy to help point you in the right direction (as above) it should be considered untested and unsupported. |
|
Thanks for the detailed reply! I’ve opened an issue on GitHub. Not using MER, is there an alternate to the group_size method that I can use to get the qty of each specific ticket type being purchased? |
|
I don’t think there is a function you can use to pull the qty of all ticket types, you would need to loop over each registration and count the tickets for each type of ticket you find (a little similar to how you would need to work with MER above). If you include that question in your issue above the developers can point you in the right direction. |
|
The support post ‘Recording the number of tickets purchased by a user per event to database’ 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.