Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Pretty sure this is a bug, a client has asked for a simplified system to display an image for product swatches.
All working as intended until you clear the image from the metafield from the product, which should stop displaying the image, however the image stays - outputting the value of the field still displays the media GID for the image, so it seems the value isn't actually being cleared from the product metafield data.
Simplified code example:
{% for swatch in product.metafields.swatches.products.value %}
{% assign swatch_img = swatch.metafields.swatches.image %}
<a class="swatch" href="{{ swatch.url }}">
<span style="{%- if swatch_img -%}background-image: url('{{ swatch_img | img_url: '30x30' }}');{%- endif -%}background-color: {{ swatch.metafields.swatches.colour }}"></span>
</a>
{% endfor %}
I'll add some validation as a workaround, but assuming this isn't intended.
Solved! Go to the solution
This is an accepted solution.
When I refreshed the product page in the admin, the image had reappeared in the image metafield, so seems that it is not always correctly saved when you delete it.
Re-deleted and re-saved the product sorted it 😅
This is an accepted solution.
When I refreshed the product page in the admin, the image had reappeared in the image metafield, so seems that it is not always correctly saved when you delete it.
Re-deleted and re-saved the product sorted it 😅
We are having this same exact issue. The solution noted here does work eventually, but it's really not a great solution and for sure a bug in the backend.
When we go to clear the metafield and click "save" the metafield shows as empty (which we want it to be), but it's still populated on the front-end. We can see that the metafield is still being populated even though it's clear (and saved) on the backend.
The only solution is to reload the product in the backend a couple times. Then add a new value and clear it again. It's somewhat a shot in the dark each time.
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