Add a custom class to variation options displaying “Out Of Stock” in Woocommerce
问题 I'm using "How to add variation stock status to Woocommerce product variation dropdown" answer code to show the text "In Stock" or "Out of stock" according to the stock status of the variation. This is what I get: I need to add a custom class only to these variants that showing text "Out of Stock". how can I do it? Emanuele 回答1: The following code will add the class outofstock to <option> html tag when the variation is "Out of Stock": // Function that will check the stock status and display