Support

Home Forums Event Espresso Premium Execute custom code only once on event thank you after registering to event

Execute custom code only once on event thank you after registering to event

Posted: October 18, 2024 at 12:09 am

Viewing 5 reply threads


cryamerica

October 18, 2024 at 12:09 am

Hi,
Is there way to execute custom code or function only once on event thank you page after registering the event? At present using the action ‘AHEE__thank_you_page_overview_template__top’ we are executing the custom code on event thank you page but here the problem is whenever we try to edit attendee information or update edit info after registration on thank you page again custom function also execusting based on Regsiter id or is there a way to run the code only once when any user register to the event or update any attenedee info again for same event on the event thank you page. Let me how to execute any function only on event thank you page.


Tony

  • Support Staff

October 22, 2024 at 3:26 am

Hi there,

May I ask what the code is doing here? There may be a better hook to use depending on what you are doing.

…is there a way to run the code only once when any user register to the event or update any attenedee info again for same event on the event thank you page.

Run the code once but on registration OR updating attendee info? So the code wouldn’t run just once in this case?

Let me how to execute any function only on event thank you page.

The hook you are using only runs on the thank you page already.

But, it sounds like you only want it to run on the initial registration, but then also on update?


cryamerica

October 25, 2024 at 12:16 am

This reply has been marked as private.


Tony

  • Support Staff

October 25, 2024 at 4:44 am

So, is this based on a payment rather than the thank you page?

If so I’d looked into using:

AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful

Which runs on a successful payment within a transaction and is passed the EE_Transaction and EE_Payment object. That doesn’t run within the thank you page so it doesn’t matter how many times that loads/registrations are edited.


cryamerica

October 27, 2024 at 11:28 pm

This reply has been marked as private.


Tony

  • Support Staff

October 28, 2024 at 9:36 am

The hook is passed the EE_Transaction it applies to within the callback of the hook, so your code won’t work as your replacing it using the reg_url_link (which isn’t set on that request).

This is the hook call:

do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful', $transaction, $payment);

Currently, you’re hooking in using the default priority and argument count:

add_action( 
    'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful',
    'custom_donation_insert_EEEvent'
);

So your function is only passed the first argument, which is the transaction, that’s fine and you have:

custom_donation_insert_EEEvent( $transaction )

This means your function has the EE_Transaction passed to the hook within $transaction.

But then you immediately replace that with:

$transaction = EE_Registry::instance()->load_model( ‘Transaction’ )->get_transaction_from_reg_url_link();

If you are passed the transaction you don’t need to get the transaction from the reg_url_link in the URL.

The code after that point to pull in the registrations and attendees from each registration looks valid although I don’t have enough context to know if it will do what you need.

with above custom code can we get the Event Id and Attendee details?

Yes, but I’m confused here, did you not have this within your original custom function?

Viewing 5 reply threads

The support post ‘Execute custom code only once on event thank you after registering to event’ 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