WooCommerce: Disable Out of Stock Variations @ Variable Product Dropdown

A nice way to avoid user frustration is to never let them pick a product / variation that is out of stock, only to realize later they can’t purchase it.

A variable product comes with a “select dropdown” on the single product page, from which customers can pick their favorite variation. Problem is that ONLY after selecting this they will find out about price, stock status and may be able to add to cart.

Today, we’ll completely disable (grey-out) those select dropdown options (variations) that are out of stock, so that users don’t waste time and only pick one of those that are in stock. Enjoy!

In this example, thanks to my snippet, the “Medium” variation is greyed out and not selectable on the WooCommerce Single Product page (“Medium” is out of stock)

PHP Snippet: Grey-out Out of Stock Variations @ WooCommerce Single Product Page

 * @snippet       Disable out of stock variations @ WooCommerce Single
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.7
 * @donate $9     https://businessbloomer.com/bloomer-armada/

add_filter( 'woocommerce_variation_is_active', 'bbloomer_grey_out_variations_out_of_stock', 10, 2 );

function bbloomer_grey_out_variations_out_of_stock( $is_active, $variation ) {
    if ( ! $variation->is_in_stock() ) return false;
    return $is_active;

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7+.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce Customization?

Check out these free video tutorials. You can start learning how to customize WooCommerce without unnecessary plugins. Watch me code and learn by example!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a 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.

22 thoughts on “WooCommerce: Disable Out of Stock Variations @ Variable Product Dropdown

  1. Hi thanks. good snippet, but it does not work on Mac OS.

    1. This should be browser-independent. Try clearing your cookies

  2. Hi,
    do not know anyone how to hide “out of stock” child product in Product page (grouped product)

    Grouped PRODUCT
    — SUB ITEM 1 — add to cart
    — SUB ITEM 2 (out od stock) – only this item hide
    — SUB ITEM 3 — add to cart

    1. Hi Antony, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  3. Hi, speak to me like I know nothing, because I don’t!

    I have around 10 variable products, this code worked for the products with a limited number of variables (around 5-10) but I have three products with a large number of variations, around 30 and the code hasn’t worked for these. Any ideas?

    Many thanks.

    1. Hey Gemma, this is unusual. It should work for all variations. Try changing “10” with “9999”, otherwise try disabling all plugins but WooCommerce to see if it works fine – in case it’s one of those plugins creating the “conflict”. Hope this helps

      1. How did this work with Gemma Grove’s problem? I have same issue, works with small amount of variations.

        1. Have you tried with 2020 theme and no other plugin apart from Woo?

  4. It works perfectly! But how to style enabled and disabled variations? I would like to visually enhance the difference between the variations…

    1. Hi Patrick, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  5. Hey, I have tried to implement this code, but I am having some issues, would you be willing to take a look and see what might be the problem?

    note: the variable “test” is out of stock.

    1. Hello Seth, thanks for your comment! I just tested this again with Storefront theme and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with my snippet?

      To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.

      Hope this helps!


      1. Thank you, I turned everything off, I even tried the Storefront theme. It still didn’t seem to work. My dropdown box looks different from yours as well… https://www.dropbox.com/s/uaixvgrjcirbsg2/Screen%20Shot%202019-10-22%20at%204.21.08%20PM.png?dl=0

        I wonder what I’ve done wrong.

        1. Not sure ๐Ÿ˜

  6. Great addition to my websites. Work great! Thank you

    1. Awesome!

      1. I do have a wholesale quick order form on my website that replicates the WooCommerce order form cart. The code snippet doesn’t seem to get applied on this.

        Here’s a link to the quick order form where you can see the variation form used and the various are not greyed out:

        Here’s a link to a product to test with (SKUs: BC004 BC005 & BC006 are out of stock)

        How would I apply the same rule in this case?


        1. Hello Lyse, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

          1. Thank you for the offer, but I don’t think I need it that bad.

            1. No problem!

  7. Hei, that’s a really nice tweak..
    Thanks.. I wanna implement it soon on one of my client website.

    1. Great!

Questions? Feedback? Support? Leave your Comment Now!

If you are writing code, please wrap it between: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

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