How to Hide WooCommerce Product If Price Is Zero | themelocation

How to Hide WooCommerce Product If Price Is Zero?

Want to Hide Products, When Price is Zero ?

When the Product is not available OR out of stock then many store owners make the price ” O ” , It gives an expression to the user that Product is not available.

I have added two products, one of the has price zero though both products one with non-zero price and other having price zero are shown in store.

  • Go to Dashboard -> Appearance -> Editor
  • Click on functions.php
  • Add the following Code in the end of the functions file
Enter code here//Put this code in functions.php file
add_action( 'woocommerce_product_query', 'themelocation_product_query' );
function themelocation_product_query( $q ){
    $meta_query = $q->get( 'meta_query' );
        $meta_query[] = array(
                    'key'       => '_price',
                    'value'     => 0,
                    'compare'   => '>'
                );
    $q->set( 'meta_query', $meta_query );
}

Click Update to Save the file.

Open your shop page you can see the product with price zero is not shown in the products.

That’s All.

 

No comments yet.

Leave a Reply