WooCommerce PHP Beginner Requires WooCommerce

Show “Free” Instead of $0.00

Display the word "Free" for products priced at zero instead of showing $0.00.

Tested on WordPress 7.1 PHP 8.3 Updated
functions.php 6 lines
add_filter( 'woocommerce_get_price_html', function ( string $price, WC_Product $product ): string {
	if ( '' !== $product->get_price() && 0.0 === (float) $product->get_price() ) {
		return '<span class="amount">Free</span>';
	}
	return $price;
}, 10, 2 );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

Free downloads, samples and lead magnets look odd with “$0.00” next to them. “Free” is clearer and more inviting.

How it works

The woocommerce_get_price_html filter returns the price HTML shown everywhere a product’s price appears. If the price is set and equals zero, the snippet replaces it with “Free”.

Products with no price at all keep WooCommerce’s behaviour, which hides the price and the Add to cart button.

Things to watch

  • The cart and checkout still show $0.00 line totals, which is correct for an order summary.
  • Variable products with a free variation show a price range; this snippet leaves ranges alone.

How to test it

Set a product’s price to 0 and view it on the shop page. It should say “Free”.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only