How To Change the Price Of $0 Items To ‘FREE’ In WooCommerce

WooCommerceIf you are using WooCommerce (which has fast become my E-Commerce plugin of choice for WordPress), then sometimes you’ll run into the issue where you want to use the word “FREE” as the price when a product is $0.

I ran into this issue recently because I’ll probably be looking at including some free add-ons to ThirstyAffiliates eventually and wanted to make sure the templates would look proper when the price was set to 0.

I came up with this little snippet of code that you can just drop into your functions.php file in your theme. You’ll need WooCommerce installed as well, of course.

add_filter('woocommerce_free_price_html', 'changeFreePriceNotice', 10, 2);
 
function changeFreePriceNotice($price, $product) {
	return 'FREE';
}

Hope this helps if you’re looking to do the same and have your prices show as “FREE” instead of an ugly $0.

Looking for a coding job? See our job listings page. Click here to view →

About Josh Kohlbach

Josh is a programmer, entrepreneur and the founder of Code My Own Road. He started this website to help programmers with business stuff and also to get things straight in his head. You can read more about Code My Own Road and Josh on the About page

,

7 Responses to How To Change the Price Of $0 Items To ‘FREE’ In WooCommerce

  1. Smittyhead July 17, 2013 at 6:24 pm #

    This is almost everything that I have been trying to find out how to do. The only thing else is that I need it to show up in all thumbnail views like the “related products” and “latest products” views.

    If you can help me with that, you will be my hero.

  2. Carsten August 27, 2013 at 1:06 am #

    Hello Josh,
    I have the following problem. I run a shop under WordPress with WooCommerce 2.0.13.
    I do not want the prices to be displayed from the start. If the “price” is not filled in by me, I get the message “FREE”. I want to avoid this message. I want that the field remains “empty” not even zero, nothing.. only empty. How do I do that?
    I use an additional plugin that allows the customer to enter his own price.
    i will be happy if you can help me
    Carsten

    • Josh Kohlbach August 27, 2013 at 8:14 am #

      Hey Carsten,

      Have you tried implementing the above code and just returning an empty string instead of the word FREE? It probably wouldn’t get rid of the element itself though so it depends on how you have styled the price with CSS as to if this is a workable solution for you.

  3. Nic December 12, 2013 at 7:55 pm #

    Thanks so much for this code. It worked brilliantly! So glad to have people like you around when I type my questions into Google :)

  4. Jimmy February 12, 2014 at 2:59 pm #

    Sweet! This works awesome. What if I wanted to display different “free” messages for different items? Say I wanted products a, b, and c to show “free” but products x, y, and z to show “no cost to you?”

    • Josh Kohlbach February 12, 2014 at 3:26 pm #

      You’d have to do it either by inspecting the product itself and checking it’s title/slug or, what I’d rather personally would be to use the product category which means you can assign a different free text to any category you like.

      This is completely untested but you could probably do something like:

      add_filter('woocommerce_free_price_html', 'changeFreePriceNotice', 10, 2);
       
      function changeFreePriceNotice($price, $product) {
      	$terms = get_the_terms( $product->ID, 'product_cat' );
      	$freetext = 'FREE';
       
      	// Check if appropriate product category
      	foreach ($terms as $term) {
      		if ((strcasecmp($term->slug,'my-cat-slug') == 0) {
      			$freetext = 'No cost to you!'
      		}
      	}
       
      	return $freetext;
  5. Tori Tran June 4, 2014 at 3:36 am #

    tks, it work.

Leave a Reply

Read more:
How I Pumped 80+ Visitors Within 24 Hours To My Very First Blog Post

When anyone starts a blog, we're all on a level playing field. We start with a big fat 0 on...

Close