Support

Home Forums Event Espresso Premium Booking Fee Hack not working now?

Booking Fee Hack not working now?

Posted: June 22, 2018 at 4:23 pm

Viewing 1 reply thread


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

  • Support Staff

June 25, 2018 at 6:30 am

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

Viewing 1 reply thread

The support post ‘Booking Fee Hack not working now?’ 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