• Resolved alessio17pa

    (@alessio17pa)


    In WooCommerce I have added a custom fee to cart, with the following code:

    function prefix_add_discount_line( $cart ) {
    
        $discount = $cart->subtotal * 0.15;
    
        $cart->add_fee( __( 'Pagamento Eolie') , $discount, true, 'Eolie Iva 22%' );
    
    }
    add_action( 'woocommerce_cart_calculate_fees', 'prefix_add_discount_line' );

    But I need to not add this fee to cart total.

    In the cart page I have those totals lines (example):

    Subtotale: €15.00
    Tassa Carrello: €5.00
    Pagamento Eolie: €2.48
    Iva 10% (stimati per Italia): €1.50
    Eolie Iva 22% (stimati per Italia): €0.54
    Totale: €24.52

    The total must exclude (always) Pagamento Eolie and Eolie Iva 22% (stimati per Italia) and the total result is €21.5

    Thx

Viewing 5 replies - 1 through 5 (of 5 total)
  • If you mean you need a negative fee, change

    $discount = $cart->subtotal * 0.15;
    to
    $discount = $cart->subtotal * -0.15;

    So the result would be


    Pagamento Eolie: -€2.48

    Totale: €22.04

    I dont know about Eolie Iva 22% (stimati per Italia) though, what is adding it? Would need to change to negative as well.

    Thread Starter alessio17pa

    (@alessio17pa)

    Thanks for your answer.
    If I go to put the negative value I get this thing

    Subtotale €15.00
    Tassa Carrello €5.00
    Pagamento Eolie 15% -€2.48
    Iva 10% €1.31
    Totale €18.84

    The field disappears Eolie Iva 22% (stimati per Italia): €0.54

    The correct total should be € 21.5.
    I should find ways to add the fields
    Pagamento Eolie: €2.48
    Eolie Iva 22% (stimati per Italia): €0.54
    without going to change the total to be kept at € 21.5

    VAT 22% Aeolian would be the VAT calculated on Aeolian payment.

    • This reply was modified 5 years, 10 months ago by alessio17pa.

    An option then could be to use both positive and negative fees simultaneously (with negative one including the “Eolie Iva” value, e. g. -3.02 in this case). Although that might look confusing to the customers.

    $discount = $cart->subtotal * 0.15;
    $cart->add_fee( __( 'Pagamento Eolie') , $discount, true, 'Eolie Iva 22%' );
    
    $discount = $cart->subtotal * 0.15 * -1.22;
    $cart->add_fee( __( '??? whatever ???') , $discount, true, '' );

    The extra fee line could be hidden with CSS or Javascript, but it would be more trouble to hide it in order emails and My account though.

    Just a thought, can you make the numbers part of description (so the
    buyer can read) but leave numbers in corresponding price column as 0?

    John

    Thread Starter alessio17pa

    (@alessio17pa)

    this would be a nice solution, indeed it would be excellent.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add a custom fee to cart without showing it in WooCommerce cart total’ is closed to new replies.