You may want to hide all out of stock products (including variations added by our Show Single Variations plugin) from your WooCommerce catalog. In this post I’ll show you a couple of ways to do it; using your own code or using a global WooCommerce Setting. Take note of your version of WooCommerce, as the code based option is different between versions.
Hide Out of Stock products for WooCommerce 3.0.0 and above
WooCommerce changed the way visibility settings are applied to products in version 3.0.0 and above. As such, the code is slightly different to hide them from the catalog. If you’re using a version of WooCommerce greater than 3.0.0, then simply add the following snippet:
Product visibility is now handled in the form of a taxonomy, rather than post meta. So the above snippet will show all products as long as they are not set to outofstock. This includes product variations.
Psst! Want to show product variations on your shop pages?
Try the 14-day free trial of WooCommerce Show Single Variations and display product variations in your WooCommerce shop pages as though they were simple products.
This just adds a new meta query to the main query that says only show products that don’t have an out of stock status. Sorted!
Hide Out of Stock products using the WooCommerce global setting
If you want less control, but a much more simple solution, you can just toggle the WooCommerce setting which will do all of this for you. Navigate to WooCommerce > Settings > Products > Inventory, and check Hide out of stock items from the catalog. Doing this will hide out of stock items everywhere on your site; in recently viewed widgets, shortcodes, search, catalog pages. Everywhere!