Support

Home Forums Event Espresso Premium Question about using a custom submit action

Question about using a custom submit action

Posted: March 30, 2023 at 3:37 pm

Viewing 3 reply threads


mbeede@tracom.com

March 30, 2023 at 3:37 pm

In my registration website I am extending the “submit registration” functionality to make some external web service calls. So I have this simple PHP…

function my_custom_submit_action( $spco, $data)
{
// The stuff I need to do
}
add_action(‘AHEE__EE_Single_Page_Checkout__process_attendee_information__end’,’my_custom_submit_action’, 10, 2);

So my page flow:
1st: my EE Event page displays which has an introduction to our training and a dropdown list of quantity. Then I click continue.

2nd: my Registration page displays providing a form for attendee information (FN, LN, email, etc.). Then I click continue.

3rd: my Checkout/Payment page displays which provides a form for my Paypal Payments Pro credit card information.

Here’s the issue. The custom submit function above is getting called after the 2nd screen submit, before the 3rd screen displays. But I can’t make the web service calls until after payment is done on the 3rd screen.

So i need some code in the custom submit function to distinguish between the 2nd screen submit, and the 3rd screen submit. Something along the lines of this, a slug or something?

if ( ! $checkout instanceof EE_Checkout || ! $checkout->current_step instanceof EE_SPCO_Reg_Step || ! $checkout->next_step instanceof EE_SPCO_Reg_Step ) {
return $submit_button_text;
}
if ( $checkout->next_step->slug() == ‘finalize_registration’ ) {
$submit_button_text = ‘Submit Payment’;
}

Can you tell me how I can distinguish between the submits ???

Thanks, Mark


Tony

  • Support Staff

March 31, 2023 at 5:38 am

Hi there,

Here’s the issue. The custom submit function above is getting called after the 2nd screen submit, before the 3rd screen displays. But I can’t make the web service calls until after payment is done on the 3rd screen.

Then, in short, you’re using the wrong hook 🙂

So i need some code in the custom submit function to distinguish between the 2nd screen submit, and the 3rd screen submit. Something along the lines of this, a slug or something?

Well, no, because AHEE__EE_Single_Page_Checkout__process_attendee_information__end ‘fires’ at the end of the attendee_information SPCO step (the second screen as you call it), the above snippet just checks for valid reg steps. But your hooking in BEFORE the finalize step has started so you’ll never get what you need to from there.

What you need is to switch to a hook that fires after the finalize registration step.

For example:

AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed


mbeede@tracom.com

March 31, 2023 at 11:14 am

Tony – Using that new hook worked. But now I have another issue. When I used the other hook the code below worked to get the different objects I need from EE. Now that I have the new hook calling this code the $checkout object is Null(0). Do I need to get the checkout object another way now?, or is there a better way to get these objects that I need?

function registerParticipant()
{
global $attendeeList;

// We need to get a few objects from Event Espresso
$checkout = EE_Registry::instance()->SSN->checkout();
if ( $checkout instanceof EE_Checkout )
{
$transaction = $checkout->transaction;

// There could be more than one registration
foreach ($transaction->registrations() as $registration)
{
if ($registration instanceof EE_Registration)
{
$attendee = $registration->attendee();
$event = $registration->event();
// $ticket = $registration->ticket();

// Build a new attendee object and add it
$newAttendee = new Attendee();
$newAttendee.setFirstName($attendee->fname());
$newAttendee.setLastName($attendee->lname());
$newAttendee.setEmailAddress($attendee->email());
$attendeeList[] = $newAttendee;
}
}
}


Tony

  • Support Staff

April 3, 2023 at 6:51 am

AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed

Should be passed an instance of EE_Checkout as the first parameter so in your example above it would have been in $spco

Check what class you have within $spco, you should be able to pull the transaction directly from that rather than through the SSN.

Viewing 3 reply threads

The support post ‘Question about using a custom submit action’ 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