Woocommerce Display Total Discount / Savings at Cart

Displaying the total price and the discount could pose some difficulties for WooCommerce so, I have discussed how to display Woocommerce Total Discount / Savings at Cart. let’s have a look how to run it.

Here is my code, Add this following line of code in your theme’s functions.php file of your active child theme (or theme) and Save the file.

 function wc_discount_total() {
   global $woocommerce;
    $discount_total = 0;
      
    foreach ( $woocommerce->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 = ($regular_price - $sale_price) * $values['quantity'];
        $discount_total += $discount;
        }
    }        
    if ( $discount_total > 0 ) {
    echo '
    '. __( 'You Saved', 'woocommerce' ) .'
    '
    . wc_price( $discount_total + $woocommerce->cart->discount_cart ) .'
    ';
    }
}
add_action( 'woocommerce_cart_totals_after_order_total', 'wc_discount_total', 99);
add_action( 'woocommerce_review_order_after_order_total', 'wc_discount_total', 99);

Leave a Comment

Scroll to Top