Hide Out of Stock Products from Your WooCommerce Catalog Pages

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.

Get Free Trial

Hide Out of Stock products for older WooCommerce versions

For older versions of WooCommerce (versions before 3.0.0), just add the following snippet:

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!

Leave a Reply

37 Comments on "Hide Out of Stock Products from Your WooCommerce Catalog Pages"

avatar
  Subscribe  
newest oldest most voted
Notify of
mmice
Guest

Hi! I have Woocommerce 3.0.6, and the snippet for old versions works awesome, though the one for new versions doesn’t

Tim Griffin
Guest

What about the related product display? I used to be able to do this pre-3.0 in the related.php template. What I want is to display out of stock product everywhere EXCEPT in the related products list on single product. Suggestions?

shreyans jain
Guest

I am looking for the exact same thing. please let me know if you find a solution

Tim Griffin
Guest

I don’t have a solution yet – here is the related.php template file that was working prior to WooCommerce 3.0
https://gist.github.com/ano

Still looking for a solution that works on 3.0+

JermaineHercules
Guest

Hello, I’ve been looking for something like this but instead you check if the product has a variation which is out of stock then hide the parent. So far I have this https://gist.github.com/ano

A.Samad Ghanchi
Guest

I want all out of stock products shows in last and all feature product shows first … is this possible ?

Christophe Hollebeke
Guest

Both snippets doesn’t work for me on a new clean webshop with Woocommerce 3.1.1 🙁

Drew Malaki
Guest

Do you have solution on woocommerce 3.1.1, when the setting to hide out stock is checked yes its working but the catalog or archive page pagination is broken but when I make the out of stock display the pagination is correct. example in a page it should display 10 items but some page is 6 out 10 items display only. Suggestions?

Rub Fox
Guest

I need some help running the code on specific page, I want to have one page displaying all the products including the ones out of stock and other page displaying only the product on stock, the first is easy using the Woocommerce settings, but the make the second one to show only products on stock?

Amal Graafstra
Guest

What about hiding products that have no regular price set (blank price, not $0/free)

Leonardo Wyskiel
Guest

Looking for this too! Can anybody help? Thanks!

Alexander Skibinskiy
Guest

Hey, James! I have a store: http://www.leador.ro/butic, we sell unique products (1 item only) I want to have an option that will allow manually to hide from catalog OUT of stock products but in the same time make out of stock products visible for SEO. Do you have a plugin for that?

V. Ionescu
Guest

Hi,
Need to hide out-of-stock products, but not those that have been sold out today, last week, or last 30 days. Meaning if it is sold out right now, still need to show it.
Any clue?

Heng See Keat
Guest

Hi James, can i know do u have any solution to hide “out of stock” products in Homepage/Main Page only?

Omanhene Cocoa Bean Company
Guest
Omanhene Cocoa Bean Company

Running Woo 3.3.1 (latest version of Woo and WP) and this php snippet does not seem to work. Has it been updated recently? I am not seeing it throw any php errors. How does one go about debugging something like this if there are no php errors in the log or onscreen? If someone else could weigh in and just confirm that it does still work fine for them on 3.3.1, it would help me to know how to proceed.

Omanhene Cocoa Bean Company
Guest
Omanhene Cocoa Bean Company

The top version does not seem to work for the latest version of WooCommerce. Since this thread is quite old, before I kill myself trying to debug this (which I am ill equipped to do), can anyone weigh in on whether this snippet is still working for them when using WP ver 4.9.4 and WooCommerce 3.3.1? Or is there some other solution that has evolved in the last 6 months?

And/or any tips on how to debug something if it is not throwing any errors? Thanks in advance for listening in on this old thread!

Bjornen
Guest
About hiding out of stock (OOS) products when performing a search query, when using a filter or a widget such as product attribute and why it’s not possible as of right now. Or, maybe it is? 1) Attributes (small, medium, large or red, green and blue) are terms. 2) The terms are not directly tied to a ‘variation’, they are tied to a parent variable product. 3) When querying products, they look at the parents only. 4) They cannot look at the variations because the variations are not assigned to the term. 5) Since the query cannot look at the… Read more »
mark
Guest

thank you . ive used the code in my website but there is question!
products will be hide on google too ?
i dont want to lose google search