WooCommerce: Hide Free Products [Code Snippet]

Are free products cluttering your WooCommerce store? Or are they so many, that you have no intention of manually setting them to “catalog visibility: hidden” one by one and need a proper shortcut?

Well, this guide will walk you through effective methods to conceal them, enhancing your store’s overall aesthetic and user experience.

Discover how to strategically hide $0 products from the shop / category / archive pages using WooCommerce custom code or dedicated plugins – enjoy!

Another case study may be the one I use on this same website – I sell online courses but also give access to their free versions, and clearly I don’t want these to show in the shop page. So, let’s hide them with a short snippet!

PHP Snippet: Hide $0 Price Products @ WooCommerce Shop / Category / Tag / Search / Archive Pages

/**
 * @snippet       Remove Free Products @ Woo Shop
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 9
 * @community     https://businessbloomer.com/club/
 */

add_action( 'woocommerce_product_query', 'bbloomer_hide_products_0_price', 9999, 2 );
  
function bbloomer_hide_products_0_price( $q, $query ) {
	if ( is_admin() ) return;
	$meta_query = $q->get( 'meta_query');
	$meta_query[] = array(
		'key' => '_regular_price',
		'value' => 0,
		'compare' => '>',
	);
	$q->set( 'meta_query', $meta_query ); 
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

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