Posted: November 28, 2020 at 4:08 pm
Hello so I’ve had a look around the forum and I’ve found maybe a handful of questions that come close to this, I even found some documentation for the get_all() function but things generally seem scattered on the topic Im going to ask about. So basically, what I’m trying to accomplish is within the thank you page’s content, I am attempting to fetch and display emails for attendees associated with the transaction. Here is a link to a github repo where I inserted the relevant snippet of code from my functions.php file. https://github.com/carlofabyss/SCCDS-EE-Attendees/blob/main/minifunctions.php So I approached this in a pretty procedural way, first by trying to get relevant data that’s being posted to this event And then by doing a query for transactions using the get_all function which has a parameter referencing the transaction id and then iterating through the results to attempt to get the ATT_EMAIL value. So I tried to do so in the same way that some of the documentation says to do for ATT_ID, but for the life of me nothing has worked past this point. So I was wondering if you guys could guide me in the right direction for this one. There’s probably some stuff in this code that doesn’t need to be here either but I’m just focusing on getting the relevant data right now. |
|
I am also using EE4 |
|
Hi there, Without trying to bash your code here, there is a fair amount wrong with that code.
Why The Meaning Now becomes It makes more sense now that you’re pulling the registrations from the transaction into
None of this is needed, your using the EE_Transaction to pull all of the registrations linked to that transaction, to then pull an EE_Transaction using the TXN_ID from each of the regs (which will be exactly the same for them all) to then use get_all on the EEM_Transaction model to pull the exact same EE_Transaction that is currently passed to the filter. So, This:
Is backwards within Event Espresso, the EE_Transaction groups the registrations so you use the EE_Transaction to pull EE_Registrations, then loop over the registrations to pull the data relevant to the specific registrations (including the attendee as that is related to the registration). Your looping over ‘transactions’ (which will actually just be one) and then using the transaction, to pull the first related registration (which make sense, but not within this loop) to pull the attendee etc. Again, my intention is not to pick away at your code here but if I don’t give you the above details you’ll be going around in circles for nothing. You need to take a look at the documentation for the model system here: https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System The reason I say that is the models make this really simple to do, but you obviously need to understand the models to do it. In this case, most of your code above can be replaced with:
With regards to your See So your whole snippet becomes something like:
Using the models to pull the data in the way it is intended to be makes the code much easier to follow here. What I usually recommend you do when trying to find the methods on the objects you have available is use kint: https://wordpress.org/plugins/kint-debugger/ Wrap the object in
Would have given you a full list of the methods available on the object, such as Side note – all of the code above is untested, I’ve written it here on the forums based on your snippet, there may well be a typo or syntax error above that I’m missing. |
|
Thanks yes Tony no worries on knocking of the code, you are absolutely right, this is something of a frankenstein of resources that I came across and thus why I eventually came here for help. Essentially yes I didn’t quite get the structure of the object model and just went off of intuition and attempting to decode the array that got spit out. I’ll go ahead and try out your suggestions and report back with a yay or a nay ๐ |
|
I think we can mark this a resolved. Tony was awesome and pretty much knocked out the query on the first try. Your suggestion about the kint debugger is also awesome, I was already able to move further along on what this is supposed to become. Revealing methods on certain objects using d($varname) sheds alot of light on the structure of EE objects. |
|
Great, I’m glad it worked well for you. As for Kint, I’m a fan ๐ If you’re using an IDE like PHPStorm you get access to a lot of info already, but I often still use Kint to throw a variable to the page and play around with it. One additional tip with Kint and the EE Models is don’t use the + button…. ever. Because the models group other models together if you hit the + button (top left) on any of the sections it automatically expands all children within that section and that can be a lot of elements. Depending on what you’re running it on it can load so many elements it crashes the browser but, the simple workaround is to click on the element name itself to open just that section, then again on any child elements you need to view and so on. |
|
The support post ‘Attempting to fetch Attendees email address on successful registration’ 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.