WooCommerce: Slashed Cart Subtotal if Coupon @ Cart

This is a nice snippet to let users know what the original cart amount was by slashing the cart subtotal and showing the cart subtotal after discounts on the same line (Cart totals > subtotal).

You can then hide the coupon code line if you wish!

WooCommerce: show slashed original and discounted subtotal @ Cart

PHP Snippet: show slashed original and discounted subtotal @ WooCommerce Cart

/**
 * @snippet       Cart subtotal slashed if coupon applied @ WooCommerce Cart
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
add_filter( 'woocommerce_cart_subtotal', 'bbloomer_slash_cart_subtotal_if_discount', 9999, 3 );

function bbloomer_slash_cart_subtotal_if_discount( $cart_subtotal, $compound, $cart ){
   if ( $cart->get_cart_discount_total() > 0 ) {
		return wc_format_sale_price( $cart->get_subtotal(), $cart->get_subtotal() - $cart->get_cart_discount_total() );
	}
   return $cart_subtotal;
}

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.

If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

6 thoughts on “WooCommerce: Slashed Cart Subtotal if Coupon @ Cart

  1. I just want to say thank you for sharing all these useful snippets for free. I learned a lot on how to access WC objects, etc. from your code and your hooks reference pages. I was coding a big project and kept having to look up how to do X and Y, to which the answer seemed to always be, “just use this plugin!”

    No!! No more!!! Plugins just are bloat and want to give me stupid popups I keep dismissing to sell me crap I don’t want. I’ve become more confident in coding things for myself thanks to looking at these snippets so I don’t have to deal with that nonsense every time I need simple functionality. Thank you very much!

  2. Hi Rodolfo, very nice thank you! It doesn’t consider the savings from the bundles. A little update would be great 🙂

    Regards,
    Marc

    1. Hello Marc, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  3. Hi rodolfo,

    Thank you for this snippet to display cart sub total at front end, Is there any way to do same at backend. When someone applied a coupon to order. its not displaying sub total. only displaying discount amount, tax and total amount after discount.

    Discount: $12.00
    Shipping: $0.00
    Order total: $12.00

    1. Hey Sunny, thanks for your comment! Yes, I’m sure this is possible. The function would be similar but you need to find the “hook” that corresponds to the order total in the admin 🙂

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

Your email address will not be published.