Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Last active July 29, 2022 11:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pebblo/0b3b28c9d0c52d5425fa167da1f1a622 to your computer and use it in GitHub Desktop.
Save Pebblo/0b3b28c9d0c52d5425fa167da1f1a622 to your computer and use it in GitHub Desktop.
Example of how to hook into SPCO's attendee_information reg step and do some additional processing which can prevent the submission BEFORE spco has processed the data.
<?php
function attendee_information__process_reg_step($process_reg_step, $reg_step, $spco) {
// Set the ID of the question you want to check the value of here.
$question_id_to_check = 17;
// Pull the transaction from checkout.
$transaction = $spco->checkout->transaction;
// Sanity check to confirm we have a
if($transaction instanceof EE_Transaction) {
// We need to process the primary registrants reg questions, to do that we need
// the reg_url_link for the primary registrant.
$primary_reg_link = $transaction->primary_registration()->reg_url_link();
// No process the data from the reg_step
$valid_data = $reg_step->valid_data();
// Pull the primary registrant's answers using the reg_url_link we pulled earlier.
$primary_reg_question_groups = $valid_data[ $primary_reg_link ];
// Loop over each question group assigned to the primary registrant and pulls it's questions.
foreach($primary_reg_question_groups as $group => $questions) {
// Within each group process the questions to find one with our matching ID.
if(!empty($questions[$question_id_to_check])){
// Do additional processing to confirm value here!
// return any falsey value to stop the processing,
// any truthy value will allow processing.
$our_question_value = $questions[$question_id_to_check];
if($our_question_value == 'stop') {
$process_reg_step = false;
break;
}
}
}
// Halt processing, add an error.
if( !$process_reg_step ) {
$error = 'SPCO has been stopped before registrations have been processed';
EE_Error::add_error(esc_html__($error, 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
}
}
// Always return ptocess
return $process_reg_step;
}
add_filter('AHEE__Single_Page_Checkout__process_reg_step__attendee_information__process_reg_step','attendee_information__process_reg_step', 10, 3);
function process_attendee_information__end($reg_step, $valid_data) {
$reg_step->checkout->redirect = true;
$reg_step->checkout->redirect_url = 'https://google.com';
$reg_step->checkout->json_response->set_redirect_url($reg_step->checkout->redirect_url);
return;
}
add_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end','process_attendee_information__end', 10, 2);
@talhaimam
Copy link

Note: $question_id_to_check is supposed to be a string as the $questions array is a type (string) => type (string) associative array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment