Getting variant ID of first variant that matches option1 (color)

Highlighted
New Member
2 0 0

I'm working on a store that routinely has products with both color and size options. I'm trying to implement color swatches for product cards in collection views, and I'd like the swatches to link to the variant ID of the first variant that matches the color. (e.g. show swatches for the red, blue, and green colors, and have each of those link to the first variant that matches the color, - likely resulting in linking to the variant for red/small, blue/small, green/small respectively.)

 

I've found decent documentation on listing the values of option1 and option2, but I can't seem to find anything explaining how I might do something along the lines of "give me the first variant id that matches 'option1 = red'"

 

Appreciate any help or insight anyone is able to provide! 

0 Likes