Do you offer a discount or coupons code on your woocommerce store and want to show total savings to your customers?
Guess What, I have a solution for you.
How to Show Total Savings on Cart and Checkout Page
In order to show savings after all the discounts and coupons are applied, You need to add the following code in your theme’s functions.php file. After you add the below code snippet customers will see their total savings under the Total Amount.
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 '<tr class="cart-discount">
<th>'. __( 'Your Savings', 'woocommerce' ) .'</th>
<td data-title=" '. __( 'You Saved', 'woocommerce' ) .' ">'
. wc_price( $discount_total + $woocommerce->cart->discount_cart ) .'</td>
</tr>';
}
}
add_action( 'woocommerce_cart_totals_after_order_total', 'wc_discount_total', 99);
add_action( 'woocommerce_review_order_after_order_total', 'wc_discount_total', 99);
Why You should show total Savings to Customers
Most likely you offer some kind of discount coupons or probably the just lowered price or put some items on sale and,
when the customer see how much money they are saving it gives them confidence that they are getting a good deal.
A study conducted by Dr. Paul J. Zak, a professor of neuroeconomics at Claremont Graduate University in Sothern California found out that brands and retailers benefit from the fact that coupon users shop more frequently and have bigger baskets sizes.
In addition to that coupons actually physically affect our bodies; they make us feel good.
So, If customers are not using coupons but still see how much money they are savings after you lower prices on inventory triggers the same response.
WHERE TO ADD THIS CODE?
You need to paste the above code snippet into your theme’s functions.php file. Which you can find in Dashboard >> Appearance >> Editor
OR
You can access the file via FTP. Just go to directory where you Install WordPress >> Wp-Content folder >> Themes >> Your active theme folder >> functions.php
If you think it was valuable in teaching shows how Total Savings on Cart and Checkout Page, Please support us on Twitter and Facebook
Have any question? Don’t forget to leave a comment below.
that was awesome… as i wanted.
That’s wonderful. I am glad it was helpful.
That is exactly I have been looking for a couple of days. Thanks!
Glad it was helpful to you ?
thank you so much bro.
how to change the color of text to red or green just to highlight…
You can use CSS to change background like this
It is very good, but it does not show for active coupons.
Only for products with prices on offer.
Once I remove the offer price products, “You Saved” disappears, even with discount coupons applied.
Yes, You are right; it’s only for if you have products on sale with both sale and regular price present.