Hide Products with 0 price in WooCommerce Shop
Use Case Scenario:
An online store has created and activated several products with “0” price. The store don’t want to display these “0” price product in the Shop page but WooCommerce will display these “0” products since they’re status is active. Hiding them using “Category” is not an option since the “0” price products belongs to a category that has a similar product with regular a regular price.
The code snippet below will address that specific requirement in the use case instead of buying a WordPress plugin.
Open functions.php in wordpress theme directory folder inside wp-content->themes->theme name folder then copy and paste the code below inside functions.php
add_action( 'woocommerce_product_query', 'whc_product_hide', 9999, 2 );
function whc_product_hide( $woo, $query ) {
if ( is_admin() ) return;
$meta_query = $woo->get('meta_query');
$meta_query[] = array(
'key' => '_regular_price',
'value' => 0,
'compare' => '>',
);
$woo->set( 'meta_query', $meta_query );
}
Watch the video tutorial in YouTube
Support WeHelpCode by subscribing to our YouTube Channel
This is really interesting, You are a very skilled blogger.
I have joined your feed and look forward to seeking more
of your great post. Also, I have shared your web site in my
social networks!
my web site; nordvpn coupons inspiresensation; wall.sh,
nordvpn special coupon code 2025 350fairfax
Appreciate this post. Will try it out.