product.has_only_default_variant example appears to have an error

Highlighted
New Member
1 0 0

In the documentation for the Liquid object "Product", the example either has a little error or is misleading.

Under the product.has_only_default_variant, the example suggests to use a variable called variant and get the id from it but the variant which isn't defined above the code example would necessarily return an empty string

May I suggest to change the value from {{ variant.id }} to to {{ product.first_available_variant.id }}?

My client was wondering why this wasn't working and it seemed so obvious I couldnt see it for a while until it dawned on me. Just trying to help out the community

 

{% if product.has_only_default_variant %}
  <input name="id" value="{{ variant.id }}" type="hidden">
{% else %}
  <select name="id">
    {% for variant in product.variants %}
      <option value="{{ variant.id }}">{{ variant.title }}</option>
    {% endfor%}
  </select>
{% endif %}

 

 

0 Likes