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!
PHP Snippet: show slashed original and discounted subtotal @ WooCommerce Cart
/**
* @snippet Cart subtotal slashed if coupon applied @ WooCommerce Cart
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @testedwith WooCommerce 6
* @community https://businessbloomer.com/club/
*/
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;
}
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!
Awesome!
Hi Rodolfo, very nice thank you! It doesn’t consider the savings from the bundles. A little update would be great 🙂
Regards,
Marc
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!
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
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 🙂