[EDIT: it actually works when adding the code in functions.php and omitting the changes in code WC files. Important: it only works when ONE attribute exists. However when there are 2 attributes (size & color for instance) then it doesn't work because it's not about out-of-stock variations anymore but about variation combinations, and indeed WooCommerce is completely clueless in this common scenario. Note that there seems to be no available plugin currently to address this very obvious problem either. Great.]
Since 2.0 WooCommerce either hides out-of-stock product variations (an obvious problem since clients have then no way to know about their existence) or displays them just as in-stock variations (also a problem because clients are then systematically disappointed to find out the variation is out-of-stock after clicking purchase).
This thread includes a solution to grey out the out-of-stock product variations:
Presumably to be added to functions.php
:
add_filter( 'woocommerce_variation_is_active', 'grey_out_variations_when_out_of_stock', 10, 3 );
function grey_out_variations_when_out_of_stock( $grey_out, $variation_id, $id ) {
$variation = get_product( $variation_id );
if ( ! $variation->is_in_stock() )
return false;
return true;
}
To be done in plugins/woocommerce/includes/class-wc-product-variation.php
:
Change:
return apply_filters( 'woocommerce_variation_is_active', true, $this->variation_id, $this->id );
to:
return apply_filters( 'woocommerce_variation_is_active', true, $this );
Also change:
return apply_filters( 'woocommerce_variation_is_visible', $visible, $this->variation_id, $this->id );
to:
return apply_filters( 'woocommerce_variation_is_visible', $visible, $this->variation_id, $this->id, $this );
Yet although it reportedly works, in my case the out-of-stock variations are displayed the same as the others and I also have a warning:
Warning: Missing argument 3 for grey_out_variations_when_out_of_stock() in ...\functions.php on line 600
What am I doing wrong?