Adam
June 22, 2018 at 4:23 pm
Hi,
We have been using your software for well over a year now. This hack that we installed has suddenly stopped charging a booking fee for no apparent reason? This went unnoticed for about 2 weeks.
https://gist.github.com/joshfeck/0e10424fff36bd62bcd72a4c76cd0687
Our code which is included in our child themes function file:
//* Funtion to add a booking fee to every tyransaction in event espresso
/**
* 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 =
array(
// name for surcharge that will be displayed, ie: 'printing fee'
'name' => 'Booking fee',
// unique code used to identify surcharge in the db, ie: 'print-at-home-fee'
'code' => 'ticket-booking-fee',
// 'fee for printing tickets'
'description' => 'Our Company Name',
// surcharge amount
'unit_price' => 2.00,
// whether or not tax is applied on top of the surcharge
'taxable' => false,
);
// 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;
}
EE_Registry::instance()->load_helper( 'Line_Item' );
$pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal( $grand_total );
$pre_tax_subtotal->add_child_line_item(
EE_Line_Item::new_instance( array(
'LIN_name' => $surcharge_details[ 'name' ],
'LIN_desc' => $surcharge_details[ 'description' ],
'LIN_unit_price' => (float) $surcharge_details[ 'unit_price' ],
'LIN_quantity' => 1,
'LIN_is_taxable' => $surcharge_details[ 'taxable' ],
'LIN_order' => 0,
'LIN_total' => (float) $surcharge_details[ 'unit_price' ],
'LIN_type' => EEM_Line_Item::type_line_item,
'LIN_code' => $surcharge_details[ 'code' ],
) )
);
$grand_total->recalculate_total_including_taxes();
return $checkout;
}
Tony
June 25, 2018 at 6:30 am
Add New Note to this Reply
Hi there,
Is that all of the code?
It should have this on the next line:
add_filter( 'FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', 'bc_ee_apply_transaction_surcharge' );
I tested the above (after adding the additional line of code) and it worked find for me – http://take.ms/B4k2f