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

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

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.

10 thoughts on “WooCommerce display FREE if price is zero ($0.00) or not set”

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

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

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

  4. 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)

      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!

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.