Skip to content

Instantly share code, notes, and snippets.

@odessy
Last active September 11, 2025 15:39
Show Gist options
  • Save odessy/a44b9b9de4984c61f2b3cec9a94eed9a to your computer and use it in GitHub Desktop.
Save odessy/a44b9b9de4984c61f2b3cec9a94eed9a to your computer and use it in GitHub Desktop.
Shopify metaobject swatches on product page
<fieldset class="radio__fieldset" style="margin-bottom: 12px;">
<legend class="radio__legend" aria-label="{{ 'home_page.onboarding.color' | t }}">
<span class="radio__legend__label">{{ 'home_page.onboarding.color' | t }}</span>
</legend>
{% for color_item in product.metafields.shopify.color-pattern.value %}
{% if color_item %}
<radio-swatch class="swatch__button{% if settings.swatches_squares %} swatch__button--square{% endif %}">
<label {% if color_item.color != null %} data-swatch style="--swatch: {{ color_item.color }}"{% endif %}>
{% if color_item.image %}
{% render 'image', img_object: color_item.image.value, width: 34, wh_ratio: 1 %}
{% endif %}
<span class="visually-hidden value">{{ color_item.label | downcase }}</span>
</label>
</radio-swatch>
{% endif %}
{% endfor %}
</fieldset>
{% assign color_item = product.metafields.shopify.color-pattern.value | first %}
{% if color_item %}
<fieldset class="radio__fieldset" style="margin-bottom: 12px;">
<legend class="radio__legend" aria-label="{{ 'home_page.onboarding.color' | t }}">
<span class="radio__legend__label">{{ 'home_page.onboarding.color' | t }}</span>
<span data-option-value="" data-swapper-target="">{{ color_item.label }}</span>
</legend>
<radio-swatch class="swatch__button{% if settings.swatches_squares %} swatch__button--square{% endif %}">
<label {% if color_item.color != null %} data-swatch style="--swatch: {{ color_item.color }}"{% endif %}>
{% if color_item.image %}
{% render 'image', img_object: color_item.image.value, width: 34, wh_ratio: 1 %}
{% endif %}
<span class="visually-hidden value">{{ color_item.label | downcase }}</span>
</label>
</radio-swatch>
</fieldset>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment