How To Hide The Product Price When Price Zero

Hide The Product Price When Price Zero

Woo-commerce displays product prices on the shop page and product detail page. Woocommerce product price is the most crucial part of the e-commerce store. Product price is one of the main elements for the customer side, whenever a customer buys a product it’s not looking good on the shop page or product detail page. When the product price is zero, it is better to hide it.

Write the following code in your child theme functions.php file.

function hide_product_price_display( $price ) {
    $clear = trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(html_entity_decode(strip_tags($price))))));
    if($clear == "0 00"){
      return '';
    }
    return $price;
  }
add_filter( 'woocommerce_get_price_html', 'hide_product_price_display' );
add_filter( 'woocommerce_cart_item_price', 'hide_product_price_display' );

Output:

Submit a Comment

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

Subscribe

Select Categories