WooCommerce: Display Total Discount / Savings @ Cart & Checkout

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 CustomizeWoo.com FREE
 * @author        Rodolfo Melogli, BusinessBloomer.com
 * @testedwith    WooCommerce 8
 * @community     https://businessbloomer.com/club/
 */

add_action( 'woocommerce_cart_totals_after_order_total', 'bbloomer_show_total_discount_cart_checkout', 9999 );
add_action( 'woocommerce_review_order_after_order_total', 'bbloomer_show_total_discount_cart_checkout', 9999 );
 
function bbloomer_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 '<tr><th>You Saved</th><td data-title="You Saved">' . wc_price( $discount_total + WC()->cart->get_discount_total() ) .'</td></tr>';
	}
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: How to Fix the “Cart is Empty” Issue
    For some reason, sometimes you add products to cart but the cart page stays empty (even if you can clearly see the cart widget has products in it for example). But don’t worry – it may just be a simple cache issue (and if you don’t know what cache is that’s no problem either) or […]
  • WooCommerce: “You Only Need $$$ to Get Free Shipping!” @ Cart
    This is a very cool snippet that many of you should use to increase your average order value. Ecommerce customers who are near the “free shipping” threshold will try to add more products to the cart in order to qualify for free shipping. It’s pure psychology. Here’s how we show a simple message on the […]
  • WooCommerce: Cart and Checkout on the Same Page
    This is your ultimate guide – complete with shortcodes, snippets and workarounds – to completely skip the Cart page and have both cart table and checkout form on the same (Checkout) page. But first… why’d you want to do this? Well, if you sell high ticket products (i.e. on average, you sell no more than […]
  • WooCommerce: Disable Payment Method If Product Category @ Cart
    Today we take a look at the WooCommerce Checkout and specifically at how to disable a payment gateway (e.g. PayPal) if a specific product category is in the Cart. There are two tasks to code in this case: (1) based on all the products in the Cart, calculate the list of product categories in the […]
  • WooCommerce: Add Privacy Policy Checkbox @ Checkout
    Here’s a snippet regarding the checkout page. If you’ve been affected by GDPR, you will know you now need users to give you Privacy Policy consent. Or, you might need customer to acknowledge special shipping requirements for example. So, how do we display an additional tick box on the Checkout page (together with the existing […]

Jamie Gill

I am a Web Developer at Jamiegill.com and love HTML, CSS, JS, PHP, MySQL. I spend most days coding, playing with the WordPress core. A WooCommerce Enthusiast, in my spare time I enjoy learning more about PHP and spending time with my wife and 3 girls.

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

129 thoughts on “WooCommerce: Display Total Discount / Savings @ Cart & Checkout

  1. I adjusted code for customers with tax in their end prices on WooCommerce.

    use it here:

    /**
     * @snippet       Display Total Discount @ WooCommerce Cart/Checkout
     * @how-to        Get CustomizeWoo.com FREE
     * @author        Rodolfo Melogli, BusinessBloomer.com
     * @testedwith    WooCommerce 8
     * @community     https://businessbloomer.com/club/
     */
     
    add_action( 'woocommerce_cart_totals_after_order_total', 'bbloomer_show_total_discount_cart_checkout', 9999 );
    add_action( 'woocommerce_review_order_after_order_total', 'bbloomer_show_total_discount_cart_checkout', 9999 );
      
    function bbloomer_show_total_discount_cart_checkout() {   
       $discount_total = 0;  
       foreach ( WC()-&gt;cart-&gt;get_cart() as $cart_item_key =&gt; $values ) {         
          $product = $values['data'];
          if ( $product-&gt;is_on_sale() ) {
             $regular_price = $product-&gt;get_regular_price();
             $sale_price = $product-&gt;get_sale_price();
             $discount = ( (float)$regular_price - (float)$sale_price ) * (int)$values['quantity'];
             $discount_total += $discount;
          }
       }
    
       $coupon_discount = WC()-&gt;cart-&gt;get_discount_total();
       $coupon_discount_with_tax = WC()-&gt;cart-&gt;get_discount_tax();
       
       $discount_total += $coupon_discount + $coupon_discount_with_tax;
                  
       if ( $discount_total &gt; 0 ) {
          echo 'You Saved' . wc_price( $discount_total ) .'';
       }
    }
    
    1. Haven’t tested it, but thanks!

  2. Hi Rodolfo,

    Thanks for sharing your snippet! It works great! However I have a slight issue. I translated “You saved” with cyrillic letters in functions.php as my shop is in Bulgarian language, but it appears correct only on desktop. On mobile it keeps showing “You saved”. Can you share some workaround in order to make it appear correctly on both – desktop and mobile? I don’t see an option to translate it with Loco translate.

    Thanks!

    1. Hi Angel! You also need to change the “You Saved” string inside the “data-title” TD attribute, because that’s what displays in the Cart page on mobile. Hope this helps!

      1. Yes! Just make sure to change the data-title value as well

  3. Hi Rodolfo,

    you snippet works great, but I have an issue on mobile. My shop is in Cyrillic and after changing the “You saved” to Cyrillic it updates only on desktop. Is it possible to change it for mobile as well?

  4. Not sure if this is still active, but I was wondering if I can put a – (minus) sign before the discount number. Thanks in advance!

  5. Thank you Rodolf, but I have been receiving an error only on my cart page, not my checkout saying A non-numeric value encountered for the line

    $discount = ( $regular_price - $sale_price ) * $values['quantity'];

    Any idea on how to fix this?

    1. Thank you John, you’re right, those are considered strings by WooCommerce so PHP throws an error. Try with the updated version and let me know.

  6. How to add that “You save” text in the cart window, not the page ?

    1. Hello Fred, 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!

  7. I love this works great on desktop and on tablet but on mobile phone I just get
    “: $10”

    or whatever the amount is not
    “You Saved: $10”
    as seen on Desktop and tablet

    Any pointers ??
    Glyn

    1. This is on the Cart Page.. The Checkout shows correct on all devices

      1. Thanks Glyn. I’ve revised the snippet, take a look

        1. Magic many thanks now works on all … desktop, tablet and mobile.
          Glyn

          1. Yay!

  8. I use Woocommerce Dynamic Pricing to apply global discounts. This means that the discount is not on a product level, but on a category level. So the product technically does not have a discount, so the line

    [PHP]$discount = ( $regular_price * $sale_price ) * $values[‘quantity’];[PHP]

    Never did anything, because $sale_price assumes it’s the discounted price. But since the product has no sale price on a product level $sale_price equals 0.
    So in the end, $regular_price – 0 was multiplying with $values, and the You saved: line was way beyond the real saving.

    Anyway, what I did was define $sale_price as a decimal value that matched my global dynamic price. This is a VERY specific use, but I thought it could be useful for anyone in my situation.

    
    /* @snippet       Display Total Discount @ WooCommerce Cart/Checkout
     * @how-to        Get CustomizeWoo.com FREE
     * @author        Rodolfo Melogli, BusinessBloomer.com
     * @testedwith    WooCommerce 4.6
     * @community     https://businessbloomer.com/club/
     */
     
    add_action( 'woocommerce_cart_totals_after_order_total', 'bbloomer_show_total_discount_cart_checkout', 9999 );
    add_action( 'woocommerce_review_order_after_order_total', 'bbloomer_show_total_discount_cart_checkout', 9999 );
     
    function bbloomer_show_total_discount_cart_checkout() {
        
       $discount_total = 0;
        
       foreach ( WC()-&gt;cart-&gt;get_cart() as $cart_item_key =&gt; $values ) {         
          $product = $values['data'];
          if ( $product-&gt;is_on_sale() ) {
             $regular_price = $product-&gt;get_regular_price();
             $sale_price = 0.15;
             $discount = ( $regular_price *  $sale_price ) * $values['quantity'];
             $discount_total += $discount;
          }
       }
                 
        if ( $discount_total &gt; 0 ) {
          echo 'You Saved' . wc_price( $discount_total + WC()-&gt;cart-&gt;get_discount_total() ) .'';
        }
      
    }
    
    1. Nice

  9. Hi there,

    You are awsome thanks for your blog!

    I added this code to my functions.php but i noticed i get an error in my cart saying:

    Warning: A non-numeric value encountered in /home/****/functions.php on line 84

    I checked this line of code and found it was this line:

    $discount = ($regular_price – $sale_price) * $values[‘quantity’];

    I also noticed the total savings amount is multiplied by 10…

    Any idear to what’s going on here?

    Kind regards,

    Dominic

    1. Hi Dominic, I’ve revised the snippet, can you check again please?

  10. Hello! Thanks so much for this, works perfectly! Any way that I could add this into my customer emails?

    Thank you!

    1. Hi Joanne, 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!

  11. how to do dis in flatsome…whn trying dis code ,getting error

    1. Hi there, 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!

  12. Is there a way to make this work with Booster for WooCommerce? I’m not getting the rate conversion applied to the discount when using a different currency on a single product.

    1. Hi Leandro, 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!

  13. Hi, I noticed in this snippet, it shows the discount amount (Price – sale price), plus I see you have some code to get the discount when a coupon is applied: wc_price( $discount_total + $woocommerce->cart->discount_cart )

    However, the result of this is to display the discount (price – sale price) plus the coupon saving excluding tax. This would cause an issue if you display prices including tax. I changed the code line to the below and it seemed to work, although I am not a developer so not 100% sure it is the correct syntax. Nonetheless, I thought it is worth pointing out so that users can get the snippet to work correctly.

    wc_price( $discount_total + ($woocommerce->cart->discount_cart + $woocommerce->cart->discount_cart_tax) )

    Regards
    Sam

    1. Sorry I did not add the correct code tags in my first message : (

      Please see below but correctly:

      Hi, I noticed in this snippet, it shows the discount amount (Price โ€“ sale price), plus I see you have some code to get the discount when a coupon is applied:

      wc_price( $discount_total + $woocommerce->cart->discount_cart )

      However, the result of this is to display the discount (price โ€“ sale price) plus the coupon saving excluding tax. This would cause an issue if you display prices including tax. I changed the code line to the below and it seemed to work, although I am not a developer so not 100% sure it is the correct syntax. Nonetheless, I thought it is worth pointing out so that users can get the snippet to work correctly.

      wc_price( $discount_total + ($woocommerce->cart->discount_cart + $woocommerce->cart->discount_cart_tax) )

      Regards
      Sam

      1. Excellent thank you!

  14. Hi,
    How do I get the% sign to the left of the price when showing the discount rate? Woocemmerce original (ex 50%). What I want to do (example %50)
    Thanks.

    1. Hello Kamil, 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!

  15. I think you forget to calculate variable products:

     
    if ( ! function_exists( 'tipikala_cart_total_discounts' ) ) {
        /**
         *
         */
        function tipikala_cart_total_discounts()  {
            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();
    
                    if (empty($regular_price)){ //then this is a variable product
                        $available_variations = $_product->get_available_variations();
                        $variation_id=$available_variations[0]['variation_id'];
                        $variation= new WC_Product_Variation( $variation_id );
                        $regular_price = $variation ->regular_price;
                        $sale_price = $variation ->sale_price;
                    }
    
                    $discount = ceil(($regular_price - $sale_price) * $values['quantity'] );
                    $discount_total += $discount;
                }
    
            }
            if ($discount_total > 0) { ?>
                <tr class="discounts-total">
                    <th><?php echo esc_html__( 'Discount total', 'tipikala' ); ?></th>
                    <td><?php echo wc_price($discount_total + $woocommerce->cart->discount_cart); ?></td>
                </tr>
            <?php }
        }
    }
    
    
    add_action( 'woocommerce_cart_totals_before_shipping',	    'tipikala_cart_total_discounts', 10 );
    add_action( 'woocommerce_review_order_before_order_total',  'tipikala_cart_total_discounts', 10);
    
    1. Thank you, I haven’t tested so I trust you ๐Ÿ™‚

  16. How can we show this total savings on order page in backend. The ‘Total Discount” should show ‘Total Savings’ + ‘Coupon Discount’ + ‘Any additional Discount manually added’

    1. Hi there – thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  17. I changed your code.
    I have the bundles on my site and they did not count correctly.
    I get the total amount of products regular and subtract the total amount of the cart and shipping – so I get a discount.

    function bbloomer_wc_discount_total_30() {
     
        global $woocommerce;
          
        $discount_total = 0;
        $regular_price_total = 0;
        $shipping_cost = $woocommerce->cart->shipping_total ;
        $cart_total = $woocommerce->cart->total;
    
        foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values) {
              
            $_product = wc_get_product( $values['data'] );
                if ( $_product->is_on_sale() ) {
                    $regular_price = $_product->get_regular_price();
                    $regular_price_total += $regular_price* $values['quantity'];
                }
    
    
            }
            $discount_total = $regular_price_total - $cart_total + $shipping_cost;
         
        if ( $discount_total > 0 ) {
        echo '<tr class="cart-discount">
        <th>'. __( 'You Saved', 'woocommerce' ) .'</th>
        <td data-title=" '. __( 'You Saved', 'woocommerce' ) .' ">'
        . wc_price( $discount_total ) .'</td>
        </tr>';
        }
     
    }
    
    1. Thanks Yuriy ๐Ÿ™‚

    2. This code adds nothing to my cart page at all.
      I am struggling, as I have the Dynamic Pricing plugin installed – and neither of these code sets work. All it does is add the regular price and displays it next to the “You Saved”. Driving me nuts! lol!

    3. Thanks so much for sharing! Was encountering a php error with the original code, but this code now fixed everything! ๐Ÿ™‚

  18. Works like a charm. Thank you!

  19. Hi Rodolfo
    Thank you very much for this Nice code.

    How can i display the sum of regular prices before the discount ?
    for Example:

    Total Regular Price: 200$
    You Save: 50$ // ( This is total discount)
    Total: 150$ // (Total you pay)

    ~R

    1. Mani, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  20. Hi Rodolfo,
    I don’t know why but the code does not work for my site. Any help, please? ๐Ÿ™‚

    1. Hey David, thanks for your comment! I just tested this again with Storefront theme and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with my snippet?

  21. Hey guys, probably a stupid question, but how do I get the discount amount to show above the total, not below it?

  22. I’m using the snippet to let people donate the discount of an order (for a NGO). I did make a form with an input field to make a donation. I want to set as standard value the total discount of the order. What part of the code do I need to realize this? The code is already added to functions.php.

    1. Bussink, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  23. Hi Rodolfo, and thank you so much. Your snippets are so great! I have a small question about this snippet. I’ d like to know how to display the total saving in cart page in case of applied coupon. Please help me. Bye bye from Italy!

    1. Ciao Fabrizio, I hear it’s crazy warm over there ๐Ÿ™‚ Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  24. Hello..

    After wc 3.0, you can edit code for regular and sale price.

    
    function bbloomer_wc_discount_total() {
     
        global $woocommerce;
          
        $discount_total = 0;
          
        foreach ( $woocommerce-&gt;cart-&gt;get_cart() as $cart_item_key =&gt; $values) {
              
    		$_product = $values['data'];
    		
    		//var_dump($_product);
      
            if ( $_product-&gt;is_on_sale() ) {
    			$regular_price = $_product-&gt;get_regular_price();
    			$sale_price = $_product-&gt;get_sale_price();
    			$discount = ($regular_price - $sale_price) * $values['quantity'];
    			$discount_total += $discount;
            }
      
        }
                 
        if ( $discount_total &gt; 0 ) {
    		echo '
    		'. __( 'ฤฐndirimler Toplamฤฑ', 'nivothemes' ) .'
    		'
    		. wc_price( $discount_total + $woocommerce-&gt;cart-&gt;discount_cart ) .'
    		';
        }
     
    }
    
    
    1. Thank you so much! Snippet updated ๐Ÿ™‚

  25. hi . thanks for share
    how add this after price in single product page?
    thanks

    1. Ehsan, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  26. hello again

    I think that I solved the problem. I share the code with you:

     foreach ( $woocommerce-&gt;cart-&gt;get_cart() as $cart_item_key =&gt; $values) {
       $_product = $values['data'];
        $_quantity = $values['quantity'];
    
       $array = (array) $_product;
       $valor_publico = $array[chr(0).'*'.chr(0).'data']['price'] * $_quantity;
      $valor_privado = $array[chr(0).'*'.chr(0).'changes']['price'] * $_quantity;
      $diferencia = $valor_publico - $valor_privado;
    
    	if ( $diferencia &gt; 0 ) {
               $discount = ($diferencia);
               $discount_total += $discount;
            }
    
    1. Nice, thanks Fernando!

    2. Thank you! You are a genius!

    3. Fernando,
      the only problem with this code is that when no bulk discounts are selected via Dynamic Pricing, the code shows a saving or the subtotal. Is there a way you can fix that – if it is not too much trouble? I will really appreciate it!!

      Let me know – thanks Fernando!
      Regards
      Charles.

      1. I would also want to know about that.

  27. High Rodolfo

    I am trying to apply this snippet with woocommerce dynamic pricing. The problem is that the discounted price is inside a private array:

    Thanks in advance

  28. Hi Rodolfo,

    This works exactly as it should for the items with a sale price. But, not only are the products on my site on sale, if a customer purchases 6 or more bottles of wine, I have pricing rules setup to further discount the wine 10%.

    When I use your code, the cart page displays the sale price crossed out and then the 10% off price, but obviously the “You Saved” total is only based on the sale savings and not the 6 bottle discount.

    Do you know how I can show only the 10% discount and disregard the sale discount?

    Thanks!
    Dan

    1. Dan, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom to your bulk pricing plugin and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R

  29. Hey, sometimes I get a 500 error when I view this site. I figured you would like to know.

    1. Hey Shanelle thanks for your comment! I don’t get these 500 errors, so would you able to let me know when you get them and on what page if possible? Thanks so much!

  30. Awesome code! Thank you, it works great!

    Any chance to get this onto a product page where an item is on sale and below the price it says: “You save $x”

    Thanks

    1. Hey Red, thanks for your comment! Yes, you can calculate the discount on the product page with something similar to this: https://businessbloomer.com/woocommerce-display-discount-shop-loop-pages/ ๐Ÿ™‚

  31. I have a simple question. How do I implement the code? do I copy and paste it on my function.php or how?
    thanks

    1. Indeed Edgar! You can place this in your child theme’s functions.php file – if you need more guidance, please take a look at this video tutorial: https://businessbloomer.com/woocommerce-customization-hangout/. Hope this helps!

  32. Awesome Rodolfo! Glad I found your blog.
    In the wp-admin orders it shows “Discount: 0 (zero)”, because as you know wordpress doesn’t consider sale vs regular price a discount (only considers coupons). Can you let us know how we can tweak the “Discount” to consider it or simply add the “you saved: (value)” there?

    Thanks!

    1. Hey Pedro, thanks for your comment! Would you be able to send me a screenshot please, I’m not entirely sure what you mean here I’m afraid ๐Ÿ™‚ Thanks!

  33. Hi Rodolfo,

    I used this snippet, but there is a small issue.. When i am having only a product with no sale price in the cart, is is showing the regular price as you saved amount..I used the latest updated snippet. Can you pls help me resolve this..

    1. Hey Samrat thanks for your comment! Could you send me a screenshot to show me the error? Thanks!

      1. Great code. Thank you. I am having a similar issue.
        When there are non-discounted products in the cart, It looks like it is adding the savings on the discounted products to the full prices of the non-discounted products.
        See screenshot here: https://dl.dropboxusercontent.com/u/17516976/screenshot-savings.png

        1. Thank you Kyle for this! I will need a screenshot of the product settings as well, as this should work fine. Sure that no product has the sale price set, even if it’s the same as the regular price?

          1. It behaves the same way at my shop. Might it be related to a woocommerce update? Did you manage to find a solution?

            1. Samrat, Kyle, Sanya, I revised the code snippet. It should work now – let me know ๐Ÿ™‚

  34. Any idea how to make this code work when the sale price is $0 or Free?

    1. Hey Brad, thanks for your comment! Could you send me a screenshot please? Cheers!

      1. Hi Rodolfo,

        Thanks for the quick reply! I have attached screenshots.

        Code does work when regular price is set to $20 and sale price to $0
        https://freesunshields.com/wp-content/uploads/2016/11/Screen-Shot-2016-11-02-at-9.40.23-AM.png

        It does work when sale price is set to $1
        https://freesunshields.com/wp-content/uploads/2016/11/Screen-Shot-2016-11-02-at-9.41.00-AM.png

        1. Awesome, super helpful. You’re right, and here’s the fix (I’m also going to update the snippet in a few minutes); substitute the line:

          if ( !empty($product->sale_price) ) {
          

          with:

          if ( isset($product->sale_price) ) {
          

          Hope this helps ๐Ÿ™‚

          1. That worked. Thank you so much!!

          2. That worked. Thank you so much!!

            1. Brilliant, thanks so much for your feedback Keyvan!

  35. Hello thank you for your snipnet,

    However It seems doesn’t work on my site

    Screenshot here: https://prntscr.com/d1wf01 – sorry for Czech language but I hope you will understand. The total saved price is somehow even higher than total price…

    I used your latest code as well.

    Thank you so much for sharing and helping people!

    1. Weird ๐Ÿ™‚ Can you completely empty the cart and re-do a test please? Cheers!

  36. Hi , Thank you very much !

    How can i change this snippets for woocommerce orders ( for Invoices )?

    I think I would change The Foreacj part code , but i hav not idea !

    Thanks alot sir

    1. Hey Mani, thanks for your comment and feedback! Are you suggesting I should add the “Savings” to the WooCommerce order email notifications as well? If yes, that’s a very good idea – let me know ๐Ÿ™‚

      1. Hi Rodolfo , Thanks a lot for your response .
        Yes , I suggest to adding the ” Total Saving ” to E-mail Notifications and ” invoices ” .
        I have purchased ” Woocommerce pip” Plugin for Order Invoices and this plugin have many Hooks To add custom functions and displays their value in the invoice Html page .

        If we have a custom function to add in the functions.php file and that returns the ” Total Saving ” based on the order content ( not the cart content ) , then we can add that function to each other hooks Like E-mails and Html Invoice of woocommerce invoice plugins .

        Thank You very much !

        1. Hello Mani, I just researched the task a bit and it’s not as easy as I thought.

          First thing, the “savings” need to be saved together with the order if we want to retrieve them later in the thank you page & email notifications.

          Second, we need to work on the “woocommerce_get_order_item_totals” filter, which is responsible for displaying the Order Totals table (we would need to add one row with the value of the savings).

          I will add this to my to-write list but I’m afraid I cannot provide this fix right now – thanks for your understanding ๐Ÿ™‚

          ~R

  37. hi rodolfo, this snippet is awesome, thanks a lot, you’re rock!

    i tried it already. i found that this snippet is not responsive for mobile view. “you saved” is missing when checkout on mobile gadget.
    how to resolve this situation? what am i need to change on this snippet.

    thanks again! regards.

    1. Thank you Thomas, you’re totally right! I just updated the snippet, and added the “data-title” part to the

      , which will show on mobile view:

       <td data-title= ....
      

      Let me know ๐Ÿ™‚

      1. work like a charm, thankyou.

        anyway, based on your screencapture above. can we re-arrange the position?

        original :
        1.subtotal $150
        2.total $150
        3.you saved $17.2
        into :
        1. subtotal $150
        2. you saved $17.2
        3. total $150

        thanks

        1. Thank you Thomas!

          Try using “woocommerce_cart_totals_before_order_total” instead of “woocommerce_cart_totals_after_order_total” and let me know ๐Ÿ™‚

  38. would be amazing if we can get a snippet like this to show same message at the checkout page summary as we don’t use the cart total in the cart page ๐Ÿ™‚ Thank you!

    1. Thanks for your comment Rodrigo! Actually, this snippet already does that. The following add_action shows that same result on the checkout page:

      add_action( 'woocommerce_review_order_before_payment', 'bbloomer_wc_discount_total');
      
      1. Thanks yes it worked, didn’t realize it :). Anyway we can change the color of the “You Saved” to RED? Thank you again!

        1. Cool ๐Ÿ™‚ For changing the color, there is a class “.cart-discount” you can use in your CSS. Cheers!

  39. Also, is it possible to make the saved amount aligned in the same column as the subtotal and Total? It’s a big to the right for some reasons. Thanks again!

    1. Hey Vuster,

      Thanks for your comments! All you’re asking is possible via CSS. If you note, we have:

      
      <table class="discount-total">
      
      

      and

      
      <tr class="cart-discount">
      
      

      …so you can use those classes to edit the look, alignment and widths!

      Let me know if you manage to do so.

      R

      1. Thanks so much!
        I was able to change the color of the “saving” text. But I’m not really sure how to make the dollar amount aligned properly (on the same vertical line as the Subtotal and Total line). Could you help? Thanks.

        1. Hey, thanks for following up! I’ve slightly modified the snippet where is says “if ( $discount_total > 0 ) { echo…”. The HTML that was being generated there was creating a new table instead of “nesting” that content into the existing cart table.

          If you use the new edit, the alignment and styles will follow the ones from the cart table now. Let me know!

          Changelog:

          
          // leave above as is
          
          if ( $discount_total > 0 ) {
              echo '<tr class="cart-discount">
              <th>'. __( 'You Saved', 'woocommerce' ) .'</th>
              <td>'. wc_price($discount_total+$woocommerce->cart->discount_cart) .'</td>
              </tr>';
          
          // leave below as is
          
          
          1. Works like a charm. Thanks!!

            1. Awesome, thanks for letting me know ๐Ÿ™‚

          2. Hi again!
            But this change doesn’t carry the formatting over to the Checkout page?

            1. You’re right lol! Use this instead:

              add_action( 'woocommerce_review_order_after_order_total', 'bbloomer_wc_discount_total');
              
  40. Awesome code! Thank you.
    Is it possible to highlight or add some formatting to the “You Saved” and the amount saved?
    Like making it Red or put a box around it. Thanks!!

  41. Hey! Nice piece of Code. Very useful. Thanks

    1. You’re welcome Waqas ๐Ÿ™‚ Thanks for your feedback!

  42. I added this to my functions.php but nothing displays on the page. Any ideas?

    1. April, thanks for your comment ๐Ÿ™‚ Just wondering if any product you added to cart is on Sale? Otherwise nothing will show ๐Ÿ™‚

      1. Okay, thanks. That would be why. I was using a coupon code instead of actually placing the products on sale.

        I’ll play around with some code to see if I can get this to work when coupons are used as well.

        Thanks!

        1. ๐Ÿ™‚ Awesome! It’s a good idea to add coupon codes as well… I’ll see what I can do ๐Ÿ™‚

          1. I Agree Rodolfo, I looking for this exactly!

            1. Done! Just change:

               wc_price($discount_total)
              

              with:

               wc_price($discount_total+$woocommerce->cart->discount_cart)
              

              In this way you will also add the coupon discounts ๐Ÿ™‚

          2. You are awesome!! ๐Ÿ™‚

            I’m attending the live class now and didn’t realize you already added the code for coupon until you mentioned it. Thanks Rodolfo ๐Ÿ˜€

            1. You’re always welcome ๐Ÿ™‚

          3. Wow! Thank you very much Rodolfo. Codemaster!!

            1. Awesome, thanks for your comment Jose! Credits go to Jamie ๐Ÿ™‚

  43. Thanks for the snippet Jamie, cheers

    1. Thank you Leo for letting Jamie know ๐Ÿ™‚

    1. I agree – thank you Jamie! ๐Ÿ™‚

  44. Thanks for the info – this will come in handy!

    1. Awesome – thank you Jean ๐Ÿ™‚

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *