WooCommerce already has a setting to completely remove products/variations products when out of stock. This means they’re no longer visible on shop pages or on product pages for the variations. If your store offers products that come back in the future it is a good idea to not completely remove them. Showing variation as disabled can be an improvement to the customer experience to show there are different options available, but not available right now.
Remove Out of Stock Products
If you want to remove the products and variations that are out of stock, use the existing settings in WooCommerce Core. Head over the WooCommerce > Settings > Products > Inventory settings section. There you’ll find the ‘Out of stock visibility’ checkbox; check the box if you’d want to hide these product from the catalog, and variations from the dropdown completely.
Disable Out of Stock Variations

With just a small code snippet it is possible to check the product stock and make variations inactive. WooCommerce Core will then by default show the options in the dropdown as disabled. The snippet gives the effect shown in the screenshot.
Add Text to Out of Stock Variations
With the above addition it is not possible to select and view these variations. Add the text ‘(out of stock)’ to provide additional context as to why variations are not available/disabled.
Adding the snippet below adds this text to all disabled options. This is done through some Javascript in order to make sure it is updated accordingly. You can change the text of course in the snippet itself.
Which gives this as a result;

13 thoughts on “Disable Out of Stock Variations in WooCommerce”
Great snippet. Thank You!
Thank You Jeroen Sormani!
Hi,
What does 10 and 2 mean from this line: add_filter( ‘woocommerce_variation_is_active’, ‘ace_grey_out_variations_when_out_of_stock’, 10, 2 );?
Thank you in advance!
Hi,
Those are the priority of the filter and the number of arguments/parameters passed.
Cheers,
Jeroen
Hi. Is there a way to keep the variation clickable in order to be able to use this with https://woocommerce.com/fr-fr/products/back-in-stock-notifications/ ?
Hi,
This is the default behaviour in Woo, so you’d not want to use any of the code snippets in this post.
Cheers,
Jeroen
I have the the “problem” as iende.
Is there a way to highlight out-of-stock variations but leave them clickable?
So customers can decide weather to take a look (and subscribe to a back in stock notification) at the variant or ignore it.
I think this ist the most friendly way for customers to deal wit oos variants
Nice snippet! Very useful!! I tryied with 2 variations (colour and size) and doesn’t work. Any tip to improve the code to allow 2 or more variations?
Thank you in advance and kind regards
Hi Trulo,
Unfortunately I don’t have something readily available for multiple attributes; that is a bit more complicated scenario that this snippet can’t handle out of the box.
It may be possible but requiring a lot further customizing it.
Cheers,
Jeroen
Nice snippet! Very useful!!
Thank you
So glad I found this. It fixed my inventory issue. Thank you!
This works really great. Would it be possible instead of greying out the out of stock variations to hide them completely?
Hi Gert,
In the WooCommerce > Settings > Products > Inventory you can configure to hide out of stock products from the catalog 😉
Cheers,
Jeroen