Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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>
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025