Show “Free” for products priced “0.00” or Empty

Blog Free instead of zero price woocommerce

You need to sometime provide some of your products for free (digital products) to get some customers to signup on your website and make them a future prospective customer. 

Then you display a product which shows the price as “0.00” which is not attractive enough for encouraging your customer to place an order. The simple solution to this can be to display it as “Free”. This will definitely attract the customer and provoke him/her to provide contact details and place an order. 

The below snippet can be used on your WordPress & Woocommerce websites.

The filter in question is woocommerce_get_price_html and below script can be used to change the text.

To activate the functionality the above snippet can be added directly to your themes function.php.

But we would recommend against making changes to the functions.php, as you would have to repeat the process all over whenever there is an update to your themes.

Instead, you can use Code Snippets Plugin which is a great tool to manage all of your snippets on a single page. To learn more about Code Snippets and how to use them you can read our article here.

If you need details instructions on how to update and write to the functions.php you can refer to the article here.

/**
* @snippet       Show "Free" For Products Priced "0.00" Or Empty
* @what-for      Change Price Display for Empty Pricing
* @author        Deepak
* @testedwith    WooCommerce Version 5.1.0
*/
  
add_filter( 'woocommerce_get_price_html', 'ioc_show_price_free_zero_empty', 9999, 2 );
   
function ioc_show_price_free_zero_empty( $price, $product ){
    if ( '' === $product->get_price() || 0 == $product->get_price() ) {
        $price = '<span class="woocommerce-Price-amount amount">FREE</span>';
    }  
    return $price;
}
Add New Snippet ‹ DigitalPages — WordPress 000406

This is it, refresh your page with a zero priced product and it will display free instead of a 0.00 price. 

That’s all folks! 

Leave a Comment

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