Andy Tran

Hide the Product Price When Price Zero

by | 30 Aug, 2021 | WooCommerce, Wordpress | 0 comments

Hide price of product

By default woo-commerce displays product price in shop page and single product detail page but what to do if the product price is zero. Price is one of the most important aspects of any eCommerce store. It’s one of the main elements that customers consider when buying a product or service. It’s not looking good on your shop page when the product price is zero so it’s better to hide the price of a Product when it’s zero on the product detail page or shop page.

Woocommerce Product - Hide Price When Price is Zero

Write the following code in your functions.php file to Remove Additional CSS from the WordPress Customizer.

It is not hard to customize the WooCommerce shop page, product page, category layout, etc. to hide prices in the WooCommerce store. The easiest way is using the plugin. But if you need more flexibility, you will most likely need to apply code.
Hiding prices in WooCommerce gives you more control over who has access to pricing information on your site.

    • Login to your WordPress Admin Dashboard.
    • Now from the left sidebar go to Appearance -> Theme Editor.
    • Go to functions.php file and write below code.

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' );

Hide WooCommerce Product Price zero

After adding this code block, you will successfully hide your woocommerce Product Price When Price is Zero.

To Continue Learning,
you can refer our blogpost Create Custom Post Type – Without Plugin

Share this article...


Submit a Comment

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

The reCAPTCHA verification period has expired. Please reload the page.