In my opinion, the WooCommerce Cart table is somewhat confusing. Why isn’t the “sale price” displayed there? Well, this is a mystery!
I’m pretty confident that showing the “slashed” price would actually help your conversion rate.
So, what about 10 PHP lines in exchange for an increase in sales? Great! Here’s the snippet 🙂
PHP Snippet: Display Regular/Sale Price in the Cart Table @ WooCommerce Cart
/**
* @snippet Show Regular/Sale Price @ WooCommerce Cart Table
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @testedwith WooCommerce 3.8
* @community https://businessbloomer.com/club/
*/
add_filter( 'woocommerce_cart_item_price', 'bbloomer_change_cart_table_price_display', 30, 3 );
function bbloomer_change_cart_table_price_display( $price, $values, $cart_item_key ) {
$slashed_price = $values['data']->get_price_html();
$is_on_sale = $values['data']->is_on_sale();
if ( $is_on_sale ) {
$price = $slashed_price;
}
return $price;
}
Hello , its work for me , thx bro.
how to display it in woocommerce/orders/customer order details page (in wp admin) ?
Hey Farshad, 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!
For checkout check this page, it helped me: https://wordpressdeveloperonline.com/showing-sale-prices-in-the-woocommerce-checkout
Cool
Is there a way to show regular price and sale price in the product/category pages also? Have been googling all day for that.
Hi Fredrik, 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!
First of all, I really appreciate what you do! This really seems like something that should be built into Woocommerce. I’ve been using this snippet and it works great, but today I was sent an error about it from WordPress. Everything still looks fine but this is the error in case you have any idea what, if anything, I should do about it:
=============
An error of type E_ERROR was caused in line 20 of the file /home/treechic/httpdocs/wp-content/themes/storefront-treechic/functions.php. Error message: Uncaught Error: Call to a member function get_price_html() on null in /home/treechic/httpdocs/wp-content/themes/storefront-treechic/functions.php:20
Stack trace:
#0 /home/treechic/httpdocs/wp-includes/class-wp-hook.php(287): change_cart_table_price_display(‘
Thanks Emily. Just tested and got no error. Maybe you could simply put a check (untested):
Hi Rodolfo,
It works great, but I wonder how this can be done in the mini-cart? As far as I can see, the hook there is exactly the same as this one, but somehow it does not work.
Any idea on why this might be? Thanks!
Hi Santiago, 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!
Hi,
Old post … but this did not work for me at all. No change to the order review area. Perhaps newer version of WC is the issue.
Works perfectly for me Ryan – sorry 😐
Hi Rodolfo,
Thanks for this great blog post. I tried your code and it worked.
however, in the dropdown box of the cart from the head menu, the client now see two prices. ‘
The original and discount.
Shouldnt this dropdown box show the end price?
Maybe yes this snippet might need a tweak to make it compatible with the cart widget. 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!
Hi Rodolfo,
This snippet works only partially for me. While the initial price is now visible as intended it is displayed without being slashed. My only CSS affects color & weight. Do you have any idea of what could be wrong ?
Hey Thibault, thanks for your comment! Somewhere in your CSS there is probably a call that targets “del” (a slashed part) and hides the slash. Maybe 🙂 Unfortunately this is custom to your theme so I can’t help here. Thanks!
hi sir, i want to Underline the original price and lead price in woocommerce, can you help me?
Hey Sitranet, 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
Thanks you so much!
🙂
How do I add this to the checkout page also?
Hello Mathias, 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
How can I remove it from checkout page?
Hey Bulent, thanks for your comment! I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know 🙂
Awesome, just what I needed :), works perfectly.
Thanks Josh 🙂
This worked perfectly! Even on Woocommerce 3.0 Thanks Rodolfo!
Awesome, thank you Kodi!
Hi,
The code do not work on my site
It might due to dynamic pricing which discounted price on quantity discount.
Possible to show on 1 quantity product?
Thanks
Allan
Hey Allan, thanks for your comment! This snippet is only compatible with default WooCommerce – in your case you will need custom coding and I can’t help here via the comments 🙂
Hi Rodolfo,
I’d like to display the sale price of a product before the regular (discount) price. I know this has something to do with get_price_html. By default, this outputs something like:
regular pricesale price
I want to change the output so it looks like this (basically, the two prices are shown in a different order):
sale price
regular priceHow can I do this?
Thank you!
Hey Toggy thanks for your comment! Is this on the Cart page or on every page of the website?
Thanks for your quick response. I want on every page of the website.
Oh – I see 🙂 Yes, this is possible but unfortunately it is custom work and cannot give a complementary solution here on the blog. Hopefully I will have time to create a snippet soon 🙂 Thank you for your understanding!
Stupid question… but what file do I copy and paste these 10 lines into? Where in the file? Do I remove anything else out?
Hey Andy, thanks so much for your comment and this is definitely not a stupid question! 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/
Thanks for your quick response. Can I add it ANYWHERE in the file, and do I need to remove anything?
Hey Andrew – yes you can add it anywhere but I recommend to put it at the very bottom, before the closing line “?>” if it’s there. You don’t need to remove anything 🙂
If it’s the first time for you, make sure you have a backup of your functions.php and FTP access so you can fix things immediately if anything goes wrong.
Hope this helps!
how to display regular price and sale price both in cart-totals.php and order page
Hey Randheer, thanks for your comment! Please take a look here: https://businessbloomer.com/woocommerce-display-regularsale-price-cart-table/#comment-16449
Hello, how can you do this in the backend and in the emails that go out? Currently if the email goes out to our warehouse, they dont know if it has been discounted and only see £7.99 when the regular price is £9.99
Hey Daniel, thanks for your comment! Yes, I took a look at the WooCommerce files and indeed Emails and Thank you page have different filters than the Cart page. I’m afraid I cannot provide a complementary fix here on the blog but I recommend you take a look at the order-details-item.php file in the templates folder 🙂 Hope this helps!
Thanks for the support, do you find it strange that it reports the discounts across emails, 3rd party invoice software and the like when using the coupon system as standard, but doesn’t report this using the ‘sale discount’ system when selling one item?
Yes! I agree with you 🙂
Hi Rodolfo,
How do I style these value (price sale, slashed price) , like make it bold and smaller for example.
I tried to put the “strong” tag on your code but somehow it didnt work.
Thank you
Hey Drake, thanks for your feedback! So, to add a style to the price you’d need to “inspect element” or use “firebug” depending on what browser you need. Those prices should have a CSS class and you can then use that in your custom.CSS. If you don’t know the basics of CSS I strongly recommend to take a look at https://www.w3schools.com/css/ because CSS is a LOT of fun! Let me know 🙂