Terry Tsang

Logo - Terry Tsang
About
WooCommerce Show “Free Shipping” Only When It’s Available

WooCommerce Show FREE instead of $0.00

If you didn’t like showing a $0.00 and prefer it with the text “FREE” for the free products, you may use below code snippet.

Below is the code you may copy and paste at the bottom of functions.php where you can access it through > Theme File Editor > functions.php.

function tt_product_price_free( $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 = '' . __( 'FREE', 'woocommerce' ) . '';
		}
	}

	return $price;
}

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

Check out this Live Demo

Leave a Comment