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 %}
Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024The Hydrogen Visual Editor is now available to merchants in Shopify Editions | Summer '...
By JasonH Sep 2, 2024Note: Customizing your CSS requires some familiarity with CSS and HTML. Before you cust...
By JasonH Aug 12, 2024