I have products listed on a particular collection page, and I'm using the following link to bypass the product detail and shopping cart pages and push customers directly into the checkout process:
<a href="https://mysite.com/cart/{{ product.variants.first.id }}:1">
However, some of our products now have variants, so for those, I want to send them to the cart page to select variants (i.e. shirt size). How do I check to see if a product has variants associated with it? Right now I'm using the code below but it's not working:
{% if variant.available == true %}
<a href="{{ product.url | within: collection }}">
{% else %}
<a href="https://mysite.com/cart/{{ product.variants.first.id }}:1">
{% endif %}
Hey Nate,
You can check how many variants the product has.
{% if product.variants.size > 1 %}
I have more than one default variant
{% else %}
I have just the one default variant
{% endif %}
Now have variants and have having available variants are two different things. Did you need to check both?
Sweet...thanks Jason. At that point I just need to know if a particular product has any variants in order to push them to the product page to select a variant, then proceed with checkout. On the product page, if a particular variant (i.e. a shirt size) is out of stock, will that variant simply not show up as an option?
@Jason @Nate_Schaub
we can check the product has variant
{% if product.has_only_default_variant %}
<input id="remove_the_dis_cart_btn" name="id" value="{{ variant.id }}" type="hidden">
{% else %}
<select name="id" id="productSelect-{{ section.id }}" class="product-variants__ product-variants-{{ section.id }}">
<option selected="selected" data-var-price=" {{ product.price_min | money_with_currency }} " > Select </option>
{% for variant in product.variants %}
{% if variant.available %}
<option data-sku="{{ variant.sku }}" data-var-price="{{ variant.price | money_with_currency }}" value="{{ variant.id }}"> {{ variant.title }} {%- comment -%} - {{ variant.price | money_with_currency }} {%- endcomment -%} </option>
{% else %}
<option> Select </option>
<option disabled="disabled">
{{ variant.title }} - {{ 'products.product.sold_out' | t }}
</option>
{% endif %}
{% endfor %}
</select>
{% endif %}
@AvidBrio
Thanks for providing the solution it's working for me.
i was also worked with you you are really good experience in Shopify
User | RANK |
---|---|
211 | |
55 | |
47 | |
36 | |
23 |