|Tony||# Posted on May 15, 2018 at 4:12 am|
There’s a couple of changes I would recommend making to that snippet (although it should work just fine as is) as we now have some methods built into EE that will reduce the workload needed for this.
That’s fairly inefficient for what you are trying to do, it pulls all events related to the contact, loops over them all to pull the ID’s and builds an array of ID that is used later to search through.
You only need to know if the user has just one registration on that event, right? So you can do something like this:
Pull the most recent registration for the current post (which in this case will be an event), if that function returns an EE_Regisitration object then the user has at least one registration on the event, meaning you can do:
Try something like this:
Which should also cover cases where you also display the ticket selector on the event list itself and not just the single event page. It removes the action used to add the ticket selector from the post rather than hiding the tickets after they have been added, which is what the additional code at the bottom is for.
As mentioned, Josh’s code will work fine as is with your changes, the above just uses some newer methods to pull the data easier so its up to you which one you prefer to use 🙂