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.
Opens WPIDE on
Code
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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.