This is a nice snippet to let users know what the original cart amount was by slashing the price and showing the price after the discount on the same line (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
 * @sourcecode    https://businessbloomer.com/?p=21879
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.1.2
 */

add_filter( 'woocommerce_cart_subtotal', 'bbloomer_slash_cart_subtotal_if_discount', 99, 3 );

function bbloomer_slash_cart_subtotal_if_discount( $cart_subtotal, $compound, $obj ){
global $woocommerce;
if ( $woocommerce->cart->get_cart_discount_total() <> 0 ) {
$new_cart_subtotal = wc_price( WC()->cart->subtotal - $woocommerce->cart->get_cart_discount_tax_total() - $woocommerce->cart->get_cart_discount_total() );
$cart_subtotal = sprintf( '<del>%s</del> <b>%s</b>', $cart_subtotal , $new_cart_subtotal );
}
return $cart_subtotal;
}

Share:

Leave a Reply