1

I'm trying to hide the "order-total" section from my checkout if the total is 0.00€ (see [Pic here][1] for reference).

I tried to add a condition to the code (as you can see below) I found suggested here:
How to remove order total from cart and checkout page woocommerce

However when I try it live, it hides the field even if the cart is not 0.00€.
Here's the code:

// On checkout page
add_action( 'woocommerce_checkout_order_review', 'remove_checkout_totals', 1 );
function remove_checkout_totals(){
    cart_total = WC()->cart->get_cart_total();
    if ( $cart_total == 0 ) {
            // Remove cart totals block
            remove_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 );
    }
}

What should I do?
Thanks in advance for you help!

24/09: edit after 7uc1f3r's corrections

  • 1
    You have a typo: `cart_total` should be `$cart_total` and `if ( $cart_total != 0 )` means NOT equal to 0, so change this by `==` – 7uc1f3r Sep 23 '21 at 09:25
  • I corrected it... And we're almost there, so first all of thanks! However the code deletes the product name, is there a way to cancel only the "order-total" table? – Luca Farina Sep 23 '21 at 10:25
  • 2
    that is possible, but only if you adjust (overwrite) the template file – 7uc1f3r Sep 23 '21 at 11:05
  • I noticed code deletes order-total field even if cart is not 0.00...I'm bamboozled – Luca Farina Sep 24 '21 at 08:59

0 Answers0