Posted on

WooCommerce: Display “FREE” Instead of $0.00 or Empty Price

In older versions of WooCommerce free prices used to display as “FREE!” and products with empty prices were not publishable. Now they’ve changed this around, but I still believe “FREE” looks much better than “$0.00”. It’s much more enticing, isn’t it?

Well, here’s how you restore the old functionality – as usual it’s as simple as using a PHP filter provided by WooCommerce and overriding the default behavior.

Display “FREE” if WooCommerce Product Price is zero or empty

PHP Snippet: Display “FREE” if WooCommerce Product Price is Zero or Empty – WooCommerce


/**
* @snippet Display "FREE" if WooCommerce Product Price is Zero or Empty - WooCommerce
* @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
* @sourcecode https://businessbloomer.com/?p=73147
* @author Rodolfo Melogli
* @testedwith WooCommerce 3.4
*/

add_filter( 'woocommerce_get_price_html', 'bbloomer_price_free_zero_empty', 100, 2 );
 
function bbloomer_price_free_zero_empty( $price, $product ){

if ( '' === $product->get_price() || 0 == $product->get_price() ) {
    $price = '<span class="woocommerce-Price-amount amount">FREE</span>';
} 

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.

31 thoughts on “WooCommerce: Display “FREE” Instead of $0.00 or Empty Price

  1. hi

    how can I show the slashed regular price next to the “free” ?

    Simon

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

  2. WOW, that is awesome! Thanks you
    Is there way to get it work for Woo Product Addons 3.+ plugin?

    Thanks you

    1. Tom, 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. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  3. I just started with WooCommerce today and this was a lifesaver. Thank you.
    A hint to anybody reading comments – You can’t use this with Fields Factory – Price adjustments. It will display your modified price until the Fields Factory plugin then it will revert to $0.00. You have to exclude any price adjustments from your product even if they start as free.

    1. Thank you Mark 🙂

  4. Works perfectly on WordPress Version 4.9.8 and Woocommerce Version 3.4.5.
    Thanks

    1. Great 🙂

  5. This still works well. Thanks!!!

    1. Awesome!

  6. Hi, I have a label free on the product image “one day of art” but the product is not free: where is the problem?

    1. Hey Roberto, thanks so much for your comment! Has that product got a price?

  7. Awesome, thank you! Exactly what I needed. 🙂

    1. Excellent 🙂

  8. I’d suggest that you update this to include the tags that WC wraps its price in. This way you can maintain the same styling you apply to your products that have a price.

    Just include
    $price = ‘FREE’;

    instead of just the FREE text.

    1. Sorry. This is what I wanted to have in my previous comment:

      $price = '<span class="woocommerce-Price-amount amount">FREE</span>';
    2. Ah, excellent, thank you Jack!

  9. Hi there,

    how can I display Free also in the cart or checkout page?

    Thank you for creating this topic.

    Cheers
    Phil

    1. Phil, 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. Hello,
    Hope you are doing fine.
    Thank you for creating this topic.
    I would like to have the word ” Free ” instead of ” 0$ ” when I enter the price=0
    and ” Coming Soon ” when I leave the price=blank

    How can I do this?

    Kind Regards.
    Rahim

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

  11. Hi Rodolfo,

    Thanks for this snippet!

    I’ve just tried it on a store that has a variable product. One of the variations is free but the other costs money.

    Without the snippet the price for that product displays as 0.00 – 15.00.

    With the snippet the price shows just as FREE, not displaying the other variation price. You can still see the 15.00 when you select that variation on the dropdown, but I want to be able to see both prices on the shop and the product page i.e. FREE – 15.00.

    Is there a way to amend the code to do that?

    Cheers

    Claire

    1. Hey Claire, 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

  12. Hi ,
    works fine, I see product FREE but I also see Add to cart button.

    for the product which is FREE , I also want to remove “add to cart button” for this product , as I want to auto add it to cart based on cart total. Can you please provide code for that as well.

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

  13. Hello!

    I´m on woocommerce 3.2.3 and this snippet dont work for me.

    “Parse error: syntax error, unexpected ‘add_filter’ (T_STRING)”

    but thanks!

    1. Hey, thanks for your comment! You must have pasted some extra characters or made a syntax error – try again 🙂

    2. Hello,

      no not really.

      https://abload.de/img/woo_error0suzz.png

      or i dont see whats wrong.

    3. That looks ok to me, there must be an error elsewhere 🙂

  14. One correction: an empty price doesn’t mean that the product is free. In WooCommerce, when a product doesn’t have a price (i.e. the price is an empty string), it’s not available for purchase.

    1. Thanks very much Diego, much appreciated – you’re right 🙂

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.