This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

📣 Join our live AMA on the Future of Page Builders with Brizy's CEO! Register Now →

How to Display Discount at WooCommerce Cart Page

Updated on May 26, 2021

2 Min Read

This is the season of discounts. Every WooCommerce store is offering discounts of all description to take advantage of the holiday craze.

WooCommerce Discount Cart

However, displaying the total price and the discount could pose some difficulties for WooCommerce Single Product pages and product listings. In many cases, the price breakdown is present at the bottom of the page. However, the developers could easily present an improved breakdown that displays the price after discounts and the discounted amount.

New Customer? Claim Your 30% Off Cloudways Promo Code

Welcome to Cloudways, where your website finds the perfect hosting solution. Claim your promo code and get 30% off for 3 months on all plans!

The following code snippet will add this functionality to the WooCommerce stores. It is important to note that with appropriate modifications, this snippet could be used to display other information such as:

  • Total Sales
  • Total Orders
  • Total of All Shipping Costs
  • Total of All Discounts Used
  • Total of All Items Ordered
  • Total Sales Per Item

Put the following snippet in the functions.php:

function cw_discount() {
   global $woocommerce;
   $cw_discount = 0;
   foreach ( $woocommerce->cart->get_cart() as $cw_cart_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'];
            $cw_discount += $discount;
        }
   }
   if ( $cw_discount > 0 ) {
        echo '<tr class="cart-discount">
    <th>'. __( 'Secure', 'woocommerce' ) .'</th>
    <td data-title=" '. __( 'Secure', 'woocommerce' ) .' ">'
            . wc_price( $cw_discount + $woocommerce->cart->discount_cart ) .'</td>
    </tr>';
    }

}

add_action( 'woocommerce_cart_totals_after_order_total', 'cw_discount');
add_action( 'woocommerce_review_order_after_order_total', 'cw_discount');

Here is is how the output of the snippet would look like. As you could see, the discount is shown on a separate line.

Secure cart

Conclusion

In this article I have discussed  how to display total discount at WooCommerce cart page. with some modifications, you could display several other price attributes as well. If you need help with the code, do leave a comment below.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Owais Alam

is the WordPress Community Manager at Cloudways - A Managed WooCommerce Hosting Platform and a seasoned PHP developer. He loves to develop all sorts of websites on WordPress and is in love with WooCommerce in particular. You can email him at [email protected]

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour

CYBER WEEK SAVINGS

  • 0

    Days

  • 0

    Hours

  • 0

    Mints

  • 0

    Sec

GET OFFER

For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now