# Grey Out Out-of-Stock Variations

> Makes sold-out variations unselectable in the product options dropdowns, so customers cannot pick a size or colour you no longer have.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, variations, stock
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-disable-out-of-stock-variations/

## Code

```php
add_filter( 'woocommerce_variation_is_active', function ( $active, $variation ) {
    return $active && $variation->is_in_stock();
}, 10, 2 );
```

## Notes

Works best for products with up to 30 variations, where WooCommerce loads all variation data on the page.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Grey Out Out-of-Stock Variations" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
