Sandesh

April 27, 2020

WooCommerce: Display Product Discount in Order Summary @ Checkout

I was wondering if there’s a way to display the discount price with the original price crossed out when a product is on sale? So I wrote a code to show the price in order summary at the checkout page and cart page.

It is straightforward. WooCommerce provides a filter for item subtotal, and we are going to use that filter. In the function, we will check if the product is on sale, will multiply regular price with the item quantity, and then append it to the total amount. Isn’t it simple?

/**
 * @snippet       WooCommerce: Display Product Discount in Order Summary @ Checkout, Cart
 * @author        Sandesh Jangam
 * @donate $7     https://www.paypal.me/SandeshJangam/7
 */
 
add_filter( 'woocommerce_cart_item_subtotal', 'ts_show_product_discount_order_summary', 10, 3 );

function ts_show_product_discount_order_summary( $total, $cart_item, $cart_item_key ) {
	
	//Get product object
	$_product = $cart_item['data'];
	
	//Check if sale price is not empty
	if( '' !== $_product->get_sale_price() ) {
		
		//Get regular price of all quantities
		$regular_price = $_product->get_regular_price() * $cart_item['quantity'];
		
		//Prepend the crossed out regular price to actual price
		$total = '<span style="text-decoration: line-through; opacity: 0.5; padding-right: 5px;">' . wc_price( $regular_price ) . '</span>' . $total;
	}
	
	// Return the html
	return $total;
}

I hope this helps you.

Where to add custom PHP code?

Add the above PHP code at the end of to your child theme’s functions.php. There are many ways to add custom PHP code ( custom functionality ) to WordPress / WooCommerce website. Read this article for more information

Why this code is not working?

If you face any issue with the above code, then please let me know in the comment. I will be happy to review the code, and If it is working for you, then show me some love in the comment section.

Thank you in advance…!

Sharing is Caring!
Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on telegram
Share on whatsapp

About the Author

Sandesh Jangam is Developer, WooCommerce Expert, and Podcaster. He is working as a WordPress developer since 2014 and helping people with this blog. He loves to travel ancient temples, chilling at the beach and reading books

Join 1,000+ Subscribers

Get exclusive access to WordPress, WooCommerce tips, articles, tutorials right in your inbox.​

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on telegram
Share on whatsapp

8 thoughts on “WooCommerce: Display Product Discount in Order Summary @ Checkout”

  1. Well done, but the strike out price only show regular price excluding tax which can be confusing. The strikeout price excluding tax is lower than the sales price including tax. Do you have a fix for that?

    1. Yeah, quite confusing. It is possible to show the tax as well but it is custom work for me. Please contact me to get a quote. Thanks.

    1. Your theme must have heavily modified the WooCommerce templates. Please try to contact theme author or contact me to get a quote. Thanks.

  2. hi,
    I want to show regular price of item along with sale price in my invoice. Can you guide me plz. (Currently invoice fetches data from woocommerce order which doesn’t contain regular_price when sale_price is triggered).I m trying to learn some coding.
    thx

Leave a Comment

Your email address will not be published.

Become a WooCommerce Customization Expert and Earn More​

Get an early access notification right in your inbox.

Learn More or Register Now >>>