PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 1, 2022

[FIXED] How to get Separate Drop Down for Color and Size on collection page in Shopify?

 July 01, 2022     html, liquid, shopify     No comments   

Issue

I want to Separate Drop Down for Color and Size under the product. Also if products is not available cart button should be disabled. Below is my code but I get both color and size in one dropdown.

<form action="/cart/add" method="post">
            {% if product.variants.size == 1 %}
          
                <input type="hidden" name="id" value="{{ product.variants.first.id }}" />
            {% else %}
        <select name="id" style="display:none;">{% for variant in product.variants %}
             <option value="{{ variant.id }}">{{ variant.title }}
             </option>{% endfor %}
        </select>
            {% endif %}
            <div><button type="submit" name="add" class="btn">Add to cart</button></div>  
        </form>


Solution

{% for option in product.options_with_values %}          
   <select  class="option-selector {{option.name}}" data-var="{{forloop.index}}">             
   {% if product.available %}              
            {% for values in option.values %}
         <option value="{{values}}">{{values}}</option>
      {% endfor %}              
   {% endif %}             
   </select>            
{% endfor %}



Answered By - Anupam Mistry
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing