WooCommerce: Display Regular & Sale Price @ Cart Table

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 🙂

WooCommerce: show sale prices @ Cart Table
WooCommerce: show sale prices @ Cart Table

PHP Snippet: Display Regular/Sale Price in the Cart Table @ WooCommerce Cart

/**
 * @snippet       Show Regular/Sale Price @ WooCommerce Cart Table
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @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;
}

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: Disable Variable Product Price Range $$$-$$$
    You may want to disable the WooCommerce variable product price range which usually looks like $100-$999 when variations have different prices (min $100 and max $999 in this case). With this snippet you will be able to hide the highest price, and add a “From: ” prefix in front of the minimum price. At the […]
  • WooCommerce: Hide Price & Add to Cart for Logged Out Users
    You may want to force users to login in order to see prices and add products to cart. That means you must hide add to cart buttons and prices on the Shop and Single Product pages when a user is logged out. All you need is pasting the following code in your functions.php (please note: […]
  • 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 […]

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

46 thoughts on “WooCommerce: Display Regular & Sale Price @ Cart Table

  1. Hello , its work for me , thx bro.
    how to display it in woocommerce/orders/customer order details page (in wp admin) ?

    1. 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!

    1. Cool

  2. Is there a way to show regular price and sale price in the product/category pages also? Have been googling all day for that.

    1. 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!

  3. 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(‘

    1. Thanks Emily. Just tested and got no error. Maybe you could simply put a check (untested):

       if ( ! $values['data'] ) return $price; 
  4. 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!

    1. 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!

  5. 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.

    1. Works perfectly for me Ryan – sorry 😐

  6. 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?

    1. 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!

  7. 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 ?

    1. 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!

  8. hi sir, i want to Underline the original price and lead price in woocommerce, can you help me?

    1. 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

  9. How do I add this to the checkout page also?

    1. 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

  10. How can I remove it from checkout page?

  11. Awesome, just what I needed :), works perfectly.

  12. This worked perfectly! Even on Woocommerce 3.0 Thanks Rodolfo!

    1. Awesome, thank you Kodi!

  13. 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

    1. 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 🙂

  14. 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 price
    sale 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 price

    How can I do this?

    Thank you!

    1. Hey Toggy thanks for your comment! Is this on the Cart page or on every page of the website?

    2. Thanks for your quick response. I want on every page of the website.

      1. 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!

  15. Stupid question… but what file do I copy and paste these 10 lines into? Where in the file? Do I remove anything else out?

    1. 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/

      1. Thanks for your quick response. Can I add it ANYWHERE in the file, and do I need to remove anything?

        1. 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!

  16. how to display regular price and sale price both in cart-totals.php and order page

  17. 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

    1. 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!

      1. 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?

        1. Yes! I agree with you 🙂

  18. 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

    1. 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 🙂

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 *