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

Saturday, July 2, 2022

[FIXED] How do check whether a shopify product option is unavailable

 July 02, 2022     liquid, shopify     No comments   

Issue

I have a dropdown menu to select specific sizes and I want to show sizes with zero quantity as disabled.

{% for value in option.values %}
<option
  value="{{ value | escape }}"
  {% if option.selected_value == value %}selected="selected"{% endif %}
  {{ value }}
</option>
{% endfor %}

The questions I have seen on SO all check if variant.available or something equivalent but I want to know if there is a way to check if a particular option is available.


Solution

I think variant.available is a better option to check it is available or not something like this one

<select name="id" id="ProductSelect--{{ section.id }}" class="product-single__variants no-js">
   {% for variant in product.variants %}
   {% if variant.available %}
      <option {% if variant == product.selected_or_first_available_variant %}
         selected="selected" {% endif %}
         data-sku="{{ variant.sku }}"
         value="{{ variant.id }}">
         {{ variant.title }} - {{ variant.price | money_with_currency }}
      </option>
   {% else %}
      <option disabled="disabled">
         {{ variant.title }} - {{ 'products.product.sold_out' | t }}
      </option>
   {% endif %}
   {% endfor %}
</select>


Answered By - Onkar
Answer Checked By - Marie Seifert (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