Support

Home Forums Event Espresso Premium Approval emails send before registration is complete

Approval emails send before registration is complete

Posted: January 21, 2016 at 9:16 am


tesscoadmin

January 21, 2016 at 9:16 am

I am using the ‘AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed’ hook to automatically generate promotion codes when certain events are purchased and the registration status is approved. I have also created a custom shortcode (type is ‘EE_Transaction_Shortcodes’) that displays those promotion codes in the ‘Registration Approved’ email that is sent once the registration is finalized.

What I’m finding is that the Approval email is getting sent before the ‘finalize’ registration hook gets a chance to complete, so the promotion codes don’t exist yet and don’t appear in the email.

Is there a way I can delay the sending of the email, even by just a few seconds, so the hook has time to complete before the email is sent?


tesscoadmin

January 21, 2016 at 11:53 am

It looks like in the ‘EE_SPCO_Reg_Step_Finalize_Registration’ class the ‘_finalize_transaction’ method, which sends the emails, runs before the ‘AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed’ hook is called. What I really need is a hook inside the ‘_finalize_transaction’ method that runs before the messages are sent. Is there another hook that is called on the last registration step I could use that runs before the ‘_finalize_transaction’ method?


Tony

  • Support Staff

January 29, 2016 at 6:17 am

Hi there,

I’ve been looking over this could not find another hook you could use so I have requested some feedback from our developers.

We will update this thread with any news.


Brent Christensen

  • Support Staff

January 29, 2016 at 11:14 am

First off, “Approval emails send before registration is complete” is not true. Notification sending is pretty much the last thing to occur before being redirected to the Thank You page after completing the registration process. Reason for this is because we need all of the Transaction and Registration information to be completed and updated before sending notifications, else the content of those notices wouldn’t be correct. The reason it doesn’t appear that way to you is because you are tapping into a hookpoint that occurs almost immediately after the notifications have been triggered. So the process is more like:

* finalize all calculations and changes for the Transaction object
* finalize all calculations and changes for all of the Registration objects
* trigger notifications
* hookpoint after EVERYTHING is done (what you were hooking into)
* redirect to Thank You page

So we need to get you into the game BEFORE the notifications are triggered, but AFTER all of the data has been updated correctly.

I would recommend using the "AHEE__EE_Registration_Processor__trigger_registration_update_notifications" hookpoint which can be found in the EE_Registration_Processor::trigger_registration_update_notifications() function. This is the actual hookpoint that is used by the messaging system for sending the notifications, so it’s guaranteed that all changes to the Transaction and Registration data have been made by this point.

The first parameter that this hookpoint receives is the EE_Registration object for the Transaction’s primary registrant. The primary registrant is typically the first registrant and is the one who receives most of the registration related notices, such as payment notifications, etc. The second parameter is an array containing some other transaction related information, the contents of which can be seen by looking at the $update_params array within the EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() function.

In order for this to work correctly the way you want, you will need to hook into this action at priority 1, ie:


add_action(  'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'your_callback_function', 1, 2 );

function your_callback_function( EE_Registration $registration, $update_params = array() ) {
    // to get the transaction object
    $transaction = $registration->transaction();
    // add your code here
}

This should allow you to do everything that you want prior to the notifications being triggered, which will happen immediately after the above code runs.

The support post ‘Approval emails send before registration is complete’ 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