Home » WooCommerce: Slashed Cart Subtotal if Coupon @ Cart

WooCommerce: Slashed Cart Subtotal if Coupon @ Cart

by Tutor Aspire

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 tutoraspire.com FREE
 * @author        Tutor Aspire
 * @testedwith    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */
 
add_filter( 'woocommerce_cart_subtotal', 'tutoraspire_slash_cart_subtotal_if_discount', 9999, 3 );

function tutoraspire_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;
}

You may also like