Support

Home Forums Event Espresso Premium Add surcharge multiplied by line item quantity

Add surcharge multiplied by line item quantity

Posted: March 10, 2021 at 5:41 am

Viewing 3 reply threads


wayne

March 10, 2021 at 5:41 am

Hi All
The context for this event is that individuals can pay for an early drop off, late pick up or both early drop off and late pick up for a small additional fee.(i have not found a similar thread on the forum) I have used one of your excellent code snippets https://github.com/eventespresso/ee-code-snippet-library/blob/master/checkout/bc_ee_apply_transaction_surcharge.php and I assume the surcharge method is the best approach and is working well. However, I would like to multiply the surcharge by the qty of that ticket. The multiplication is working fine but I thought I could get the line quantity from the helper- can you point me in the right direction?.

Many thanks

EE_Registry::instance()->load_helper( 'Line_Item' );
$pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal( $grand_total );
// cant get line item quantity of the ticket
$quant = 1;
$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' => $quant,
'LIN_is_taxable' => $surcharge_details[ 'taxable' ],
'LIN_order' => 0,
'LIN_total' => (float) $quant * $surcharge_details[ 'unit_price' ],
'LIN_type' => EEM_Line_Item::type_line_item,
'LIN_code' => $surcharge_details[ 'code' ],
) )
);


Tony

  • Support Staff

March 10, 2021 at 8:53 am

Hi there,

If I understnad your question correctly, I think you are looking for:

$ticket_line_items = EEH_Line_Item::get_ticket_line_items($grand_total);

if(empty($ticket_line_items)) {
    return;
}

foreach($ticket_line_items as $tkt_line_item ) {
    echo $tkt_line_item->quantity();
}

Obviously, if you have more than one ticket type in the cart you’ll need to some additional checking here and use the ticket line item for that specific ticket but is that what you are looking for?


wayne

March 10, 2021 at 9:31 am

Smashed it Tony – Thanks


Tony

  • Support Staff

March 10, 2021 at 10:06 am

You’re most welcome.

Viewing 3 reply threads

The support post ‘Add surcharge multiplied by line item quantity’ 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