Home » WooCommerce: Display Total Discount / Savings @ Cart & Checkout

WooCommerce: Display Total Discount / Savings @ Cart & Checkout

by Tutor Aspire

If you love Ecommerce as much as I do, and are passionate about Sales Conversion Rate and reducing Shopping Cart Abandonment, today’s snippet will come in handy.

Besides, this is officially the first guest blog on Business Bloomer (have ideas? Send me your proposal here)… so let me officially introduce you to today’s author: Jamie Gill, a WordPress & WooCommerce enthusiast from Bradford, UK.

Jamie managed to code a handy snippet to display inside Cart and Checkout totals the total amount of money a customer saved (sale prices plus coupon discounts). Over the years this snippet went through several revisions, but it’s still working smoothly – enjoy!

WooCommerce: Show Total Savings / Total Discount Amount @ Cart & Checkout Pages

PHP Snippet: Show How Much Customer Saved @ WooCommerce Cart and Checkout Pages

/**
 * @snippet       Display Total Discount @ WooCommerce Cart/Checkout
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire, BusinessBloomer.com
 * @testedwith    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'woocommerce_cart_totals_after_order_total', 'tutoraspire_show_total_discount_cart_checkout', 9999 );
add_action( 'woocommerce_review_order_after_order_total', 'tutoraspire_show_total_discount_cart_checkout', 9999 );
 
function tutoraspire_show_total_discount_cart_checkout() {   
$discount_total = 0;  
foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {         
$product = $values['data'];
if ( $product->is_on_sale() ) {
$regular_price = $product->get_regular_price();
$sale_price = $product->get_sale_price();
$discount = ( (float)$regular_price - (float)$sale_price ) * (int)$values['quantity'];
$discount_total += $discount;
}
}          
if ( $discount_total > 0 ) {
echo 'You Saved' . wc_price( $discount_total + WC()->cart->get_discount_total() ) .'';
}
}

You may also like