Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I have created a metaobject for the color swatch, which contains the following fields: 1. Color Name, 2. Color Hex Code, 3. Product (for linking to the swatch). I have populated all the details, and everything seems to be set up correctly. I have successfully connected the namespace and key of the metafield. However, I'm facing an issue with the product URL: instead of showing the product handle, it displays the product variant ID. How can I fix this?
Here's the code of mine for your reference it might be issue in my code please check once.
{% if product.metafields.custom.color_swatches != blank %}
<div class="product-color-swatches" {{ block.shopify_attributes }}>
{% for color_swatch in product.metafields.custom.color_swatches.value %}
{% assign color_name = color_swatch.color_name | remove: '["' | remove: '"]' | strip %}
{% assign color_hex = color_swatch.color_hex_code | remove: '["' | remove: '"]' | strip %}
{% assign product_link_parts = color_swatch.product | split: '/' %}
{% assign product_handle = product_link_parts.last %}
<a href="/products/{{ product_handle }}" class="color-swatch-link">
<span class="color-swatch" style="background-color: {{ color_hex }};">
<span class="color-name">{{ color_name }}</span>
</span>
</a>
{% endfor %}
</div>
{% endif %}
Discover how to increase customer engagement on your store with articles from Shopify A...
By Jacqui Apr 23, 2025Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025