See if a product has variants

New Member
4 0 0

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 %}

0 Likes
Highlighted
Shopify Expert
9981 85 1492

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?

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
New Member
4 0 0

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?

0 Likes