I have this code:

add_filter( 'woocommerce_variation_is_active', 
'grey_out_variations_when_is_backorder', 10, 2 );
function grey_out_variations_when_is_backorder( $grey_out, $variation ) {

if ( ! $variation->is_in_stock() && $variation-
 >backorders_require_notification() )
    $grey_out = false;

return $grey_out;
}

that is working for Woo 2.6.X and Woo 3.X . This code works, for backorder products in WooCommerce, and makes grayout variation if is in backorder but is not in stock. Now im trying to do this, so users can identify better what product is in stock, and what is not.

  • “out of stock” + “allow, backorder but notify” = yellow background &
    can be selected.
  • “out of stock” + “DO NOT allow backorder” = red background & cannot
    be selected
  • “In stock” + (any backorder configuration) = green background & can
    be selected

I meen instead only grayout not stock products, to add some colour background in that variation, so will be better visible. How to modify my current function to work in that way? Thanks in Advance.

Read more here: Colour in Backorder Products dropdown based on stock in WooCommerce


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: