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

terrytsang

Share
Published by
terrytsang
Tags: snippets

Recent Posts

Unveiling the Mystery: Why Do We Call It ‘Startup’?

1. The Origin and The Meaning of Startup The word "start" refers to the beginning…

2 years ago

Get More Done in Less Time: 13 Must-Have AI Tools for Skyrocketing Your Productivity

=== #1: AI Chatbot === 1. ChatGPTGet Started here: https://chat.openai.comChatGPT, one of the most significant language…

2 years ago

How to Add Dashicons to WordPress Frontend

Dashicons is the official icon font since WordPress admin as of 3.8. https://developer.wordpress.org/resource/dashicons/ However, it…

3 years ago

Coffee Chat with Founder of Hai Kuang

Recently I had a great coffee chat with my old pal - Wei Ming, founder…

3 years ago

WooCommerce Custom Order Status “Processing”

Sometimes there is a need for a custom new order status for WooCommerce orders such…

3 years ago

Logo Design Ideas

Here is a list of logo branding ideas for your next business or startup:  …

3 years ago