Variant
From Shopify Wiki
A product variant (or variant for short) is a different version of a product, such as a size or a color. Without variants, you would have to treat the small, medium and large versions of a t-shirt as three separate products; variants let you treat the small, medium and large versions of a t-shirt as variations of the same product.
For a full explanation of variants, see Products, variants and options in the documentation of the product resource.
Product Variants have the following attributes:
variant.id
Returns the variant’s unique id.
Note: this is a number, not a string.
variant.title
Returns the concatenation of all the variant's option values, joined by " / ". For example, if your variant has option1 as "Large", option2 as "Red", then variant.title will return "Large / Red". If a product has just single option, then the title is simply the value of option1.
variant.price
Returns the variant’s price.
variant.compare_at_price
Returns the variant’s recommended retail price.
variant.available
Returns whether the variant is available for sale or not.
Depending on your preferences, we suggest you hide variants that are not for sale anymore OR mark them as sold out.
If variant.available returns false, this item must not be added to the cart.
Example:
{% if variant.available == true %}
We currently have {{ variant.inventory_quantity }} in stock.
{% else %}
Sold out!
{% endif %}
variant.inventory_management
Returns the variant’s inventory tracking service, e.g. shopify or shipline, or simply '' (an empty string) when the inventory stock level is not being tracked at all.
variant.inventory_quantity
Returns how many of this variants are in stock for this shop.
Note that this value will only be accurate if variant.inventory_management reports that the variant’s inventory stock level is being tracked.
variant.inventory_policy
Returns the word 'deny' or the word 'continue' — 'deny' if backordered items can't be added to the cart, and 'continue' if they can.
variant.weight
Returns the weight of the variant. This will always be in metric grams. For displaying it according to your weight system (metric/imperial) please run the variable through the weight_with_unit filter.
This product weighs {{ product.variants.first.weight | weight_with_unit }}
variant.sku
Returns the variant's SKU.
variant.option1
Returns the value of option1 for given variant
variant.option2
If a product has a second option defined, then returns the value of this variant's option2.
variant.option3
If a product has a third option defined, then returns the value of this variant's option3.
variant.options
This makes the variant options available in your theme as an array you can loop through.
It is an array of simple strings, so you can use the keyword 'contains' with it.
{% if variant.options contains 'with gift-wrap' %}
<!-- do something about it -->
{% endif %}
Displaying options in a list:
{% for option in variant.options %}
<li>{{ product.options[forloop.index0] }}: {{ option }}</li>
{% endfor %}
variant.requires_shipping
Returns true if the variant is shippable or false if it is a service or a digital good. This must be set on the product details page for each variant.
variant.taxable
Returns true if the variant is taxable or false if it is not. This must be set on the product details page for each variant.
variant.barcode
Returns the barcode value of the variant.

