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