How to Show Free instead of 0 dollars in WooCommerce

Do you want to show the “FREE” price instead of $0.00 in WooCommerce when the product is actually free? Today you are in luck because I am going to share how you can do that easily.

Showing the word Free instead of $0.00(or whatever currency you trade-in) is more noticeable to users and less confusing especially when just want to add some free products or gifts for your customers to choose from.

Or in case,

You are just trying to sell something like a “FREE + Shipping” deal for cheap items where you just make a profit from charging shipping cost rather than the actual product, showing the word Free makes perfect sense in that scenario.

Okay, enough talking let’s jump to the actual solution.

Show Free instead of $0.00 in WooCommerce

All you need to do is add the following code snippet to your theme’s function.php file and voila…

function wpglorify_price_free_zero_empty( $price, $product ) {
	if ( $product->get_price() == 0 ) {
		if ( $product->is_on_sale() && $product->get_regular_price() ) {
			$regular_price = wc_get_price_to_display( $product, array( 'qty' => 1, 'price' => $product->get_regular_price() ) );

			$price = wc_format_price_range( $regular_price, __( 'Free!', 'woocommerce' ) );
		} else {
			$price = '<span class="amount">' . __( 'Free!', 'woocommerce' ) . '</span>';
		}
	}

	return $price;
}

add_filter( 'woocommerce_get_price_html', 'wpglorify_price_free_zero_empty', 10, 2 );

when your products are on sale the above code snippet will show the regular price along with the word “Free”.

If you don’t want that kind of behavior to use the following code snippet it will only show word Free and not the regular price but don’t use both of them together.

add_filter( 'woocommerce_get_price_html', 'wpglorify_price_free_zero_empty', 100, 2 );
  
function wpglorify_price_free_zero_empty( $price, $product ){
 
if ( '' === $product->get_price() || 0 == $product->get_price() ) {
    $price = 'FREE';
} 
 
return $price;
}

Feel free to leave your comments below in case you got any questions.

5 Comments

    • Hey Javier, Thanks for pointing that out. I have updated the post and now if you put the product on sale for $0 price, it will show the original price and word Free as well.

      Depending on your theme you might need to do some styling though.

Leave a Reply

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