Site icon Experience Wordpress Developer Online – Design Develop and Maintenance Support

WooCommerce Hide the Product Price When Price Zero

By default WooCommerce display product price in archive page and single page but what to do if product price is zero. it’s not look good in your shop page when product price is zero so it’s better to hide the price of an Product when it’s zero on the product category/archive page or single product page.

so here is solution, Add below line of code in your theme’s functions.php file of your active child theme (or theme) and save the 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' );
Exit mobile version