Remove variant drop down selectors for only one variant

Highlighted
Shopify Partner
4 0 3

Hi

I'm trying to remove the drop down selectors on the product page where there is only one option in the drop down for example, a product might have a variant of colour 'Blue' but no other colours. In my example it will have other options such as size, material.

How do I hide the colour option but leave the other ones available? 

I can see the loop on product.liquid:

<select id="product-select" name='id'>
                            {% for variant in product.variants %}
                                <option value="{{ variant.id }}">{{ variant.title }} &nbsp;&nbsp;&nbsp;</option>
                            {% endfor %}      
                            </select>  

but this is calling all the variants together. I've been playing around with this but not had any success. Can someone please point me in the right direction as I'm new to  Shopify?

1 Like
Highlighted
Shopify Partner
4 0 3

Never mind, this seems to work:

 

  

   //hide any single option selectors
      $('select.single-option-selector').each(function(){
        if ($(' > option', this).length == 1){
          $(this).css('visibility', 'hidden');
          $(this).prev().css('display', 'none');
       }
      });


      

2 Likes
Highlighted
New Member
3 0 0

Hi,

Does this work still and where is the code placed? 

Thanks

0 Likes