WooCommerce display FREE if price is zero ($0.00) or not set

This code snippet allows you to change the price of a WooCommerce product to a text value such as “Free”.

Last Updated

Written By

Do you need to replace the default WooCommerce pricing label for a free product? Perhaps you offer some, if not all, of your products at no cost. Instead of showing the default WooCommerce price label of $0.00, you want to show custom text, such as the word “FREE” or “Download Now”.

Hide Prices for WooCommerce

Use our plugin to change the price label to “Free”

This is a code snippet and requires knowledge of PHP to get it working. If you’re not wanting to use code to show “Free” instead of $0 and would prefer a plugin solution instead, then checkout the Hide Prices plugin built by us. It allows you to hide prices and the add to cart button, but also replace the price with a simple text label. This text label can be used to display “Free” instead of $0.

On the WP Geeks website, we’ve done exactly that. A number of our WooCommerce plugins that are listed on our site are completely free to download and use. We really didn’t like showing a dollar value of zero and so we replaced it with the text “FREE”. It turns out, that it’s really simple to do in WooCommerce.

What is required is a quick filter to override the price of the product and replace it with the text of your choice.

Change A Free Product’s WooCommerce Price Label

Just copy and paste the following snippet in to your functions.php file and edit the label text as indicated in the snippet’s comment below.

<?php
/**
 * Display "FREE" instead of $0 if the item is free.
 *
 * @param string $price The current price label.
 * @param object $product The product object.
 * @return string
 */
function wpgeeks_price_override( $price, $product ) {
   if ( empty( $product->get_price() ) ) {
      /*
       * Replace the word "Free" with whatever text you would like. Also
       * remember to update the textdomain for translation if required.
       */
      $price = __( 'FREE', 'textdomain' );
   }

   return $price;
}
add_filter( 'woocommerce_get_price_html', 'wpgeeks_price_override', 100, 2 );

Breaking it down, we’re just checking the price of the product to make sure that it is “empty” i.e. free, and then if it is, returning different label text which in the case above is the word “FREE”.

If the product is not free, then we don’t change anything and return the original price.

It’s as easy as that. Do let us know if you run in to any issues and we will try our best to help you out.


Comments

15 responses to “WooCommerce display FREE if price is zero ($0.00) or not set”

  1. Thank you very much WP Geeks for the snippet!
    P.S.: please make sure to remove that “” at the end ?

  2. Soul Shake Avatar

    Thank you so much for this snippet, it is the only one I found that is ‘translation ready’ with the proper “__(” and text domain element. You saved my day!! Cheers!

  3. Thanks! It works perfectly. It’s a relief that it was this easy, thanks to you.

  4. Hey it’s not working on my store.I have also seen other code in the tutorial to change pricing on display https://www.cloudways.com/blog/change-woocommerce-price-display/ but still having an error. Can you please help me out?

    function cw_change_product_price_display( $price ) {
    $price .= ‘ At Each Item Product’;
    return $price;
    }
    add_filter( ‘woocommerce_get_price_html’, ‘cw_change_product_price_display’ );
    add_filter( ‘woocommerce_cart_item_price’, ‘cw_change_product_price_display’ );

    1. Hi Alvina,

      It looks like you’re appending text after the price value, instead of replacing it. Is that your intention? I’m unable to support on another sites snippet, I recommend you use the snippet above.

  5. Hello

    Thanks for the steps but I want to know something

    Is there any way to make an option in product editing page whether to show FREE or empty.

    I want both FREE & Empty in different products instead of Zero

    Waitnig for reply

    1. Absolutely Fakhrul, but it’s slightly more complex than this simple snippet 🙂 We’re actually working on a plugin which allows custom price labels for free products and they can be set on a per product basis. It should be live within the next week and it’s called “Pricing Rules”.

      Cheers,
      Matt

  6. Hi Matt,

    Any update on this plugin you just mentioned? This sounds like exactly what we have been searching high and low for – can’t believe there isn’t already a solution. Essentially we need to be able to hide the price of certain variations / display enquire or at least don’t display £0.00. Thanks!

    1. Matt (WP Geeks) Avatar
      Matt (WP Geeks)

      Hi Dr Steve!

      Good timing, we’re actually just about to release a plugin that does exactly what you need. We’re currently doing the final testing before release. Should be out tomorrow. I’ll email you the link when it’s ready.

      Cheers!

    2. Matt (WP Geeks) Avatar
      Matt (WP Geeks)

      Hi Dr Steve!

      The plugin is now ready and is called Hide Prices.

      Cheers,
      Matt

  7. I don’t know if this thread is still alive but I have a quick question. I’m setting up an amazon affiliate product in which they amazon doesn’t like you to put in a price. Except, now I get a FREE badge, over all my products.. Is there any way to remove this badge?? I’ve been at it all day….

    Thanks,
    Ricardo

    1. Matt (WP Geeks) Avatar
      Matt (WP Geeks)

      Hi Ricardo,

      You can set the word ‘FREE’ to an empty string in this line to do this:

      $price = __( ‘FREE’, ‘textdomain’ );

      Matt

  8. How can I show a background color for FREE text?

    1. Matt (WP Geeks) Avatar
      Matt (WP Geeks)

      You will need to use CSS to change the color.

  9. Is there a way to only show Free when the product price is zero and not empty? I am using a credits system and all credits products will show as free which I don’t want. I just want proucts with a price set as 0 to show as free.

Leave a Reply

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.