Support

Home Forums Event Espresso Premium add_action not fired

add_action not fired

Posted: September 15, 2016 at 8:07 am

Viewing 5 reply threads


jbrandligt2

September 15, 2016 at 8:07 am

Hi,

I’m trying to use a hook, but for some reason the add_action isn’t fired at all. This is the code I’m using:


// Create custom post on successful manual transaction
function espresso_track_successful_sale_manual( $Transaction, $status_updates ){
echo '<p><h1>=============TEST!=============</h1></P>';
// do other stuff here...
}

add_action('AHEE__EE_Transaction_Processor__manually_update_registration_statuses','espresso_track_successful_sale_manual', 10, 2);

I copy pasted the code from a working sample here: https://github.com/ds-festival/event_espresso_4_custom/blob/master/espresso_custom.php

I am using the code inside a plugin I’m working on. The plugin registers without errors and is working fine otherwise. When I register at an event using the invoice payment method, the add_action should be executed when the registration is completed. But nothing happens.

Can anyone tell me whats wrong? Thanks!


Josh

  • Support Staff

September 16, 2016 at 2:02 pm

The do_action is probably firing when it’s supposed to, but it’s in another place. The action hook you’re trying to use is fired when you apply a payment via the admin. Your example code where you tried to echo a string to the screen will result in breaking the ajax response. If you want to test the hook, you can do something like this:

function espresso_track_successful_sale_manual( $Transaction, $status_updates ){
add_option( 'did_the_action_hook_fire', 1, '', 'no' );
// do other stuff here...
}
add_action('AHEE__EE_Transaction_Processor__manually_update_registration_statuses','espresso_track_successful_sale_manual', 10, 2);

Then you go to Event Espresso > Transactions, click on a transaction, then apply a payment where you also update the payment status and registration status. Then you check the last row of your options table to verify that the option was added via your code.


jbrandligt2

September 17, 2016 at 7:54 am

Ok thanks, I will try that for testing. Seems I am using the wrong hook though. I’m writing a plugin to create a sequential invoice number. I want to store the invoice number in the meta data of a custom post which is to be created. I thought the hook I’m using was fired when upon successful registration, but apparently not. Can you tell me which hook I have to use instead?


Josh

  • Support Staff

September 19, 2016 at 7:10 pm

I’m not sure which hook you would use in that case. A few possibilities are:

AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed
or
AHEE__EE_Payment_Processor__update_txn_based_on_payment


jbrandligt2

September 28, 2016 at 12:32 am

Hi Josh,

Testing the action by writing a value to the options table worked great, thanks for the tip.
I ended up using this action hook for my plugin:
AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment
Only drawback is that in some cases it fires more then once, so I have to test if the custom post with the invoice number has already been created. But I’m a happy camper, because I can finally use sequential invoice numbering. Still I hope that someday it will be core functionality 🙂

Thanks for the support!


Josh

  • Support Staff

September 28, 2016 at 7:33 am

Still I hope that someday it will be core functionality

You are invited to do a pull request.

https://github.com/eventespresso/event-espresso-core/

Viewing 5 reply threads

The support post ‘add_action not fired’ 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