Posted on

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 customers convert better.

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

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


/**
 * @snippet       Show Regular/Sale Price @ WooCommerce Cart Table
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=20478
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.4.3
 */

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 this code?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such delicate files - if you need more guidance, please take a look at my free WooCommerce Customization video tutorial.

Does this snippet still work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free videos, tutorials and tips!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP
  • woocommerce-customize-shop-page-PHP
  • woocommerce-advanced-customization
  • how-to-edit-woocommerce-cart
  • woocommerce-customize-checkout-page-PHP
  • woocommerce-email-customization
  • woocommerce-conditional-logic

Rodolfo Melogli

Author, WooCommerce expert, WordCamp speaker and Internet marketer, Rodolfo Melogli has worked as a WooCommerce freelancer since 2011. He helps entrepreneurs and developers overcome their WooCommerce nightmares :) Rodolfo is the organiser of WordCamp Dublin, the Dublin WooCommerce Meetup, the Dublin Ecommerce Meetup and the Dublin WordPress Meetup. He enjoys interacting with people, travelling and chasing tennis & soccer balls. Of course, he loves pizza too.

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

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

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

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

  4. How can I remove it from checkout page?

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

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

    1. Awesome, thank you Kodi!

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

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

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

  9. 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: http://businessbloomer.com/woocommerce-customization-hangout/

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

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

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

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

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

    3. Yes! I agree with you 🙂

  12. 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 http://www.w3schools.com/css/ because CSS is a LOT of fun! Let me know 🙂

Questions? Feedback? Support? Leave your Comment Now!
If you're writing code, please wrap it between: [php] code_here [/php]

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.