• Hi guys,

    I’ve read countless threads and tried multiple different ways to add a simple “sold out” text to unavailable variants in the drop down menu. No success so far.

    I’ve managed to gray out unavailable variants with this code I found:

    
    function wcbv_variation_is_active( $active, $variation ) {
     if( ! $variation->is_in_stock() ) {
     return false;
     }
     return $active;
    }
    add_filter( 'woocommerce_variation_is_active', 'wcbv_variation_is_active', 10, 2 );
    

    Perhaps there’s a way to not just gray out but add text as well? Unfortunately I’m not versatile enough to do it myself, so I’m hoping for some knowledgeable inputs from some people more capable than me ??

    • This topic was modified 4 years, 2 months ago by k1p57a.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Check the HTML source of a page where you’ve got inactive variants to see what CSS class WC injects for them.
    Then you can add (for instance via Appearance → Customize → Extra CSS) a CSS rule with the class modifier ::before to add a badge.

    Thread Starter k1p57a

    (@k1p57a)

    Hey tobifjellner,

    Thanks for taking the time to answer.

    That would indeed be a wonderfully simple solution. But last I checked ::before and ::after pseudonyms would result in a child element, or am I mistaken?

    (In theory the disabled variants can easily be targeted via “#color option[disabled]“)

    Here’s the drop down HTML structure that gets generated:

    <select id="color" class="" name="attribute_color" data-attribute_name="attribute_color" data-show_option_none="yes">
    	<option value="">Choose an option</option>
    	<option value="Black" class="attached" disabled="">Black</option>
    	<option value="Pink" class="attached enabled">Pink</option>
    	<option value="Yellow" class="attached enabled">Yellow</option>
    	<option value="White" class="attached" disabled="">White</option>
    </select>

    Looking forward to your much appreciated answer.

    • This reply was modified 4 years, 2 months ago by k1p57a.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Woocommerce?|?add “sold out” text to variants’ is closed to new replies.