I have a registration form with multi checkbox question.
The options in this question is “Session 1″ ,”Session 2″,”Session 3″,”Session 4″,”Session 5″
For each selected session the fee will be the same for all :100 QAR
So I did the below code.
but i get only one additional session fee event if i choose more than one sessions
function bc_ee_determine_whether_to_apply_surcharge() {
// CHANGE $surcharge_QST_ID VALUE TO MATCH THE ID OF YOUR QUESTION
$surcharge_QST_ID = 69;
if ( isset( $_REQUEST[ ‘ee_reg_qstn’ ] ) ) {
foreach ( $registrations as $QST_ID => $response ) {
write_log(‘THIS IS THE START OF MY CUSTOM DEBUG’);
//write_log($response);
// [0] => Session 1
// [1] => Session 2
// [2] => Session 3
// [3] => Session 4
// [4] => Session 5
$result = count($response);
write_log($result);
for ($i = 0; $i < $result; $i++) {
write_log(‘value in array ‘.$response[$i]);
// value in array Session 3
// value in array Session 4
// apply the surcharge
add_filter( ‘FHEE__bc_ee_apply_transaction_surcharge__apply_surcharge’, ‘__return_true’ );
if($response[$i]===”Session 1″){
// hook into function below to set surcharge details
add_filter( ‘FHEE__bc_ee_apply_transaction_surcharge__surcharge_details’, ‘bc_ee_session1_fee_surcharge_details’);
}elseif($response[$i]===”Session 2″){
// hook into function below to set surcharge details
add_filter( ‘FHEE__bc_ee_apply_transaction_surcharge__surcharge_details’, ‘bc_ee_session2_fee_surcharge_details’);
}elseif($response[$i]===”Session 3″){
// hook into function below to set surcharge details
add_filter( ‘FHEE__bc_ee_apply_transaction_surcharge__surcharge_details’, ‘bc_ee_session3_fee_surcharge_details’);
}elseif($response[$i]===”Session 4”){
// hook into function below to set surcharge details
add_filter( ‘FHEE__bc_ee_apply_transaction_surcharge__surcharge_details’, ‘bc_ee_session4_fee_surcharge_details’);
}else{
// hook into function below to set surcharge details
add_filter( ‘FHEE__bc_ee_apply_transaction_surcharge__surcharge_details’, ‘bc_ee_session5_fee_surcharge_details’);
This is my final code (Same problem i get only latest selected value in the checkbox)
function bc_ee_determine_whether_to_apply_surcharge() {
// CHANGE $surcharge_QST_ID VALUE TO MATCH THE ID OF YOUR QUESTION
$surcharge_QST_ID = 69;
if ( isset( $_REQUEST[ ‘ee_reg_qstn’ ] ) ) {
foreach ( $_REQUEST[ ‘ee_reg_qstn’ ] as $registrations ) {
if ( ! empty( $registrations ) ) {
foreach ( $registrations as $QST_ID => $response ) {
if ( $QST_ID === $surcharge_QST_ID ) {
$result = count($response);
for ($i = 0; $i < $result; $i++) {
switch ( $response[$i] ) {
case ‘Session 1’ :
// apply the surcharge
add_filter( ‘FHEE__bc_ee_apply_transaction_surcharge__apply_surcharge’, ‘__return_true’ );
// hook into function below to set surcharge details
add_filter( ‘FHEE__bc_ee_apply_transaction_surcharge__surcharge_details’, ‘bc_ee_session1_fee_surcharge_details’ );
break;
case ‘Session 2’ :
// apply the surcharge
add_filter( ‘FHEE__bc_ee_apply_transaction_surcharge__apply_surcharge’, ‘__return_true’ );
// hook into function below to set surcharge details
add_filter( ‘FHEE__bc_ee_apply_transaction_surcharge__surcharge_details’, ‘bc_ee_session2_fee_surcharge_details’ );
break;
}// end switch
}//end for
}
}
}
}
}
}
add_action( ‘AHEE__EE_System__core_loaded_and_ready’, ‘bc_ee_determine_whether_to_apply_surcharge’, 2 );
/**
* EDIT THIS TO HOLD THE DETAILS FOR ONE OF YOUR ANSWER OPTIONS
* @return array
*/
function bc_ee_print_at_home_fee_surcharge_details() {
write_log(‘This is bc_ee_print_at_home_fee_surcharge_details’);
return array(
‘name’ => ‘Session 1’,
‘code’ => ‘session11’,
‘description’ => ‘Session 1’,
‘unit_price’ => 100.00,
‘taxable’ => false,
);
/**
* DO NOT EDIT ANYTHING EXCEPT DEFAULT SURCHARGE DETAILS
*
* bc_ee_apply_transaction_surcharge
*
* @param \EE_Checkout $checkout
* @return \EE_Checkout
*/
function bc_ee_apply_transaction_surcharge( EE_Checkout $checkout ) {
// DEFAULT SURCHARGE DETAILS – EDIT THIS
$surcharge_details = apply_filters(
‘FHEE__bc_ee_apply_transaction_surcharge__surcharge_details’,
array(
// name for surcharge that will be displayed, ie: ‘printing fee’
‘name’ => ‘shipping fee’,
// unique code used to identify surcharge in the db, ie: ‘print-at-home-fee’
‘code’ => ‘ticket-shipping-fee’,
// ‘fee for printing tickets’
‘description’ => ‘postal fee for shipping tickets’,
// surcharge amount
‘unit_price’ => 0.00,
// whether or not tax is applied on top of the surcharge
‘taxable’ => false,
)
);
// STOP EDITING
// apply the surcharge ?
if ( ! apply_filters( ‘FHEE__bc_ee_apply_transaction_surcharge__apply_surcharge’, false ) ) {
return $checkout;
}
// verify checkout
if ( ! $checkout instanceof EE_Checkout ) {
return $checkout;
}
// verify cart
$cart = $checkout->cart;
if ( ! $cart instanceof EE_Cart ) {
return $checkout;
}
// verify grand total line item
$grand_total = $cart->get_grand_total();
if ( ! $grand_total instanceof EE_Line_Item ) {
return $checkout;
}
// has surcharge already been applied ?
$existing_surcharge = $grand_total->get_child_line_item( $surcharge_details[ ‘code’ ] );
if ( $existing_surcharge instanceof EE_Line_Item ) {
return $checkout;
}
write_log(“@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@”);
write_log($surcharge_details);
write_log(“@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@”);
// i get only latest checkbox option
Can I ask why you linked to one example in your opening post, then use a completely different example in your follow ups? Those 2 functions work at different steps in the registration.
So with the first example you gave, its set up to only allow a single value from the questions to apply a ‘product’. The code needs some refactoring to allow you to select multiple items within a checkbox and then add a ‘product’ for each selected answer, take a look at this example:
If your ticket is free the Single Page Checkout Module does not build out the payment options step, the snippet above adds a charge between the attendee info and payment options step so if you don’t a ticket with a price you don’t see the charge.
Really thank you for your wonderful help and sorry for asking a lot of questions but there is any possibility to make the payment option of surcharge mandatory?
I don’t there is, I checked the code and it doesn’t appear to allow that.
When the checkout page is generated it checks if a payment is required for your registrations and if not it does not initialize the payment options steps (to reduce processing that is unneeded).
The snippet above adds a payment amount to the transaction after the above happens so the payment options steps isn’t there.
I’ll check with our developers to see if its possible to work around that but I don’t believe there is.
So right now it’s not possible to force EE to show the payment options for a free ticket, the function that checks if the transaction is free and removes the payment options steps is ran way before the surcharges are added to the registration.
However we can add a filter to the function that will allow it to be bypassed and I’ve created a ticket for for this which will be reviewed, test and released so it may be possible (all being well) to do wtih the next version of EE.
Actually, a simple filter for this isn’t going to work so for now you’ll need to use a paid ticket.
I’ve created a ticket to investigate this further but as the developers are working on other areas of the plugin this is unlikely to be added ‘soon’.
Viewing 13 reply threads
The support post ‘Add surcharge if multi select checkbox question checkbox’ 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.