How to remove price of a product when it’s zero on the category and archive page?

In Woocommerce, when a product has zero price it will display ‘Free’ instead. In this tutorial we’ll learn how to remove price of a product when it is zero.

Here is what our category and archive page looks like when a product has price equal to zero.

Shop page will look like:

woocommerce

The category page will look like:

woocommerce

And product page:

woocommerce

Now we want to remove ‘Free’ label on category and shop page. To do this add the following lines of code at the end of your functions.php file:

add_action('woocommerce_before_shop_loop_item','custom_remove_loop_price');

function custom_remove_loop_price(){

   global $product;

   if(!$product->price){

       remove_action('woocommerce_after_shop_loop_item_title','woocommerce_template_loop_price',10);

   }

}

You can access functions.php file here:

woocommerce

Save the file after placing code.

Now refresh the category and shop page and you’ll see ‘Free’ text removed.

Shop page will be:

woocommerce

And category page will look like:

woocommerce

However ‘Free’ text will still be displayed at product page.

Waqas

I hope you enjoy reading this blog post. If you want my team to do WooCommerce Maintenance for you, click here.

Leave a Comment

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