I have built several surcharge fonctions based on this example with success (4 functions up now !).
I also built a variable donation surcharge based on the above example and it worked well for one of my event wihtout any flaws. Nevertheless, trying to duplicate this fonction on another event registration question group lead to erratic results, i.e. outputting zeros or ones instead of field input value. I suspect that I do not handle global variable ($response_don_2) correctly but before spending more time debugging, I would like to have your recommendations or guidance. Here is the custom code :
$response_don_2 = 0;
function rc_ee_determine_whether_to_apply_surcharge_don_2() {
// CHANGE $surcharge_QST_ID VALUE TO MATCH THE ID OF YOUR QUESTION
global $response_don_2;
$surcharge_QST_ID = 39;
if ( isset( $_REQUEST[ 'ee_reg_qstn' ] ) ) {
foreach ( $_REQUEST[ 'ee_reg_qstn' ] as $registrations ) {
if ( ! empty( $registrations ) ) {
foreach ( $registrations as $QST_ID => $response_don_2 ) {
if ( $QST_ID === $surcharge_QST_ID ) {
if ( ( $response_don_2 > 0 ) && ( $response_don_2 < 1000 ) ) {
add_filter( 'FHEE__rc_ee_apply_transaction_surcharge__apply_surcharge_don_2', '__return_true' );
// hook into function below to set surcharge details
add_filter( 'FHEE__rc_ee_apply_transaction_surcharge__surcharge_details_don_2', 'rc_ee_don_amra_2' );
}
}
}
}
}
}
}
After digging a little further, the global variable is not responsible (at least by itself) for the strange behavior of the variable donation surcharge function.
After creating a new question and assigning it to a group of questions, I cannot mess around the question’s order inside the group of questions. If I move a question related to a surcharge, the surcharge function will stop working. If I resume the rank of the related question inside the group of questions, everything get back to normal and the function perform well again !
I can sure leave things as they are as it seems to work if I don’t modify the question’s groups but it would be a good thing to understand why it is so.
Then, you step through your custom code and check values with the above function. e.g.
write_log($variable_name);
Then test, and tail your site’s wp-content/debug.log file to check what gets logged.
Viewing 4 reply threads
The support post ‘Handling global variable for implementing surcharge custom function’ 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.
Support forum for Event Espresso 3 and Event Espresso 4.