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

Thursday, June 30, 2022

[FIXED] How to show size and colors separately in shoplify?

 June 30, 2022     shopify     No comments   

Issue

I want to display colors and sizes separately on frontend to filter the collection in shopify. But when I do, it shows color and size in same variable with slash in it.

Here is the image

enter image description here

Here is the code that i try

      <div class="size-filter clearfix mt-4">
         <h4>SIZE</h4>
         <hr>
         {% assign available_sizes = '' %}
         {% for product in collections.frontpage.products limit: limit %}
         {% for variant in product.variants %}
         {% if variant.title != 'Default Title' %}
         {% unless available_sizes contains variant.title %}
         {% if  variant.available %}
         {% capture available_sizes %}{{ available_sizes }}, {{ variant.title }}{% endcapture %}
         <div class="form-check">
            <input class="form-check-input coll-filter" type="checkbox" value="{{variant.title}}" id=""
            {% if current_tags contains tag %} checked  {%endif%}>
            <label class="form-check-label" for="">
            {{variant.title}}
            </label>
         </div>
         {% endif %}
         {% endunless %}
         {% endif %}
         {% endfor %}
         {% endfor %}
      </div>

Please help me to fix this error, i stuck here from last 3 days.

Error Solved but got this output:

enter image description here


Solution

You can do use the options_with_values object:

{% for product_option in product.options_with_values %}
  <h5>{{ product_option.name }}</h5>
  {% for value in product_option.values %}
    <input id="{{product_option|handle}}-{{value|handle}}" type="checkbox" value="{{ value }}" />
    <label for="{{product_option|handle}}-{{value|handle}}"></label>
  {% endfor %}
{% endfor %}

But you will need to write some Javascript in order to tie it to the main select which holds the variants ids.



Answered By - drip
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • 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