Add link to Vairant - for statement / liquid assistance needed

BradO
Shopify Partner
2 0 0

 

I've added a custom property at the variant level to add a small helper link to the end of the Variant name.  For example, "Variant Name (foo)", where "foo" is the link.

 

The customization is working with one exception, rather than just adding the link the the one variant it belongs to, it's adding the same link to all variants for that product.  I believe this is related to the for statement being incomplete, but I am more of a designer than a a developer so I am in need a of a little assistance.

 

The code added to product-form.liquid is below, surrounded by BEGIN and END comments, with the rest of it being unchanged.

 

Can anyone point me in the right direction so that the link is only added to the variant to which it applies, and not all variants?

 

Thank you!

 

<div class="block-swatch-list">
{%- for value in option.values -%} <div class="block-swatch"> <input class="block-swatch__radio visually-hidden" type="radio" name="option{{ option.position }}" form="{{ product_form_id }}" id="{{ option_id }}-{{ forloop.index }}" value="{{ value | escape }}" {% if value == option.selected_value %}checked="checked"{% endif %} data-bind-value="{{ option_id }}-value"> <label class="block-swatch__item" for="{{ option_id }}-{{ forloop.index }}">{{ value }}</label>
{% # BEGIN %} {% for variant in product.variants %} {% if variant.metafields.my_fields.variant_link != blank %} <span class="variantLink">{{ variant.metafields.my_fields.variant_link }}</span> {% endif %} {% endfor %}
{% # END %}

</div>
{%- endfor -%} </div>

 

 

Replies 0 (0)