WooCommerce free product: Display ‘Free’ instead of $0.00

There can be many reasons for listing free products on your Woocommerce store. It could be a sample, a free course or a giveaway.

On the recent versions of Woocommerce, if you put zero in price, or leave the price field empty, it would show the price of the product as $0.00, which definitely doesn’t look as attractive as displaying the word ‘Free’.

So if you are in a similar situation, and want to display ‘Free’ instead of $0.00, just add the following function. And if you are a non-coder, click on the download link below the code to get this script as a WordPress Plugin.

add_filter( 'woocommerce_get_price_html', 'sg_wc_free_product', 9999, 2 );
   
function sg_wc_free_product( $price, $product ){
    if ( $product->get_price() === '' || $product->get_price() == 0 ) {
        $price = '<span class="woocommerce-Price-amount amount">FREE</span>';
    }  
    return $price;
}

Download SG WooCommerce Free Product Plugin

Leave a Reply

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