finners
finners

Reputation: 885

Adding product variant title in shopify

I've got a few products that have different variants - i.e. Colour, Size, etc.

I'm trying to output the parent(?) variant title using - {{ variant.title }} but that's only outputting the variant options themselves i.e. Small, Medium, Large for Size. Is there a way to output the "Size" title and not the individual variant titles.

Sorry if that's confusing, I know I'm in the close but maybe in the wrong ball park!

Upvotes: 0

Views: 4171

Answers (2)

kmoloo
kmoloo

Reputation: 1

Using {{ product.options }} worked for this. I was able to output Size/Flavor for different products and their variant option titles.

Upvotes: 0

Dave B
Dave B

Reputation: 3248

I don't think the option titles are available on the variant object - for those you would normally look on the parent product object.

If you are printing the variant details from the context of a product page (or other situation where you already have a product object), you can use product.options or product.options_with_values to get the option category names. The option names will always be in the same order as the option values are listed on the variant, so the first value of the product.options array will be for the first item in the variant.options array.

Once an item is added to the cart, the resulting line_item object gets its own style of an options_with_values object that has the names and values of the associated options, but unfortunately this object does not appear to exist on the variant object itself.

Above links all go to the relevant Shopify Liquid reference pages

Upvotes: 0

Related Questions