Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
We've only just seen the newer 'Category Metafields' when creating a product in Shopify:
My question is: how do I access the value of this in Liquid? It would be incredibly handy to determine some display functionality based on the product category. But I can't find anything in the docs or online. Is it simply part of
product.metafields
...but with a standardised name?
Dieing to know aswell. Can't be so difficult to provide users with a basic doc upon adding new features right?
I had a response from Shopify Support when I emailed them about this, and currently it's not accessible via Liquid (or any other means, AFAIK).
They have said they might consider it as they can see the usefulness, but currently it's not possible.
Looks like i'm seeing them being used on live themes. How are they rendering them? via APIs?
I believe, dispite the feedback from shopify, that the values can actually be accessed through a "product_option_value". I only managed to do it with the option Color so far. Maybe its just that this was specifically linked somehow. Anyway. I had to add color swatches to a customer store and could access them through the product_option_value.swatch.color
It looks somewhat like this:
{% unless collection.handle == "fussmatte" %}
<div class="hkt_swatches_container">
{%- for option in card_product.options_with_values -%}
{%- for value in option.values -%}
{% assign variant = value.variant %}
{% if option.name == "Farben" or option.name == "Colors" or option.name == "Color" or option.name == "Farbe" %}
<div class="hkt_swatch_outside">
<a class="hkt_swatch" href="{{ variant.url }}" style="background-color:{{ value.swatch.color }};">
</a>
</div>
{% endif %}
{% endfor %}
{% endfor %}
</div>
{% endunless %}
Thanks so much for this 🙏. Worked perfectly after over 24 hours trying to find a solution to it.
Maurice unless I am not following, the above code only returns the product options, it has nothing to do with the category metafields.
You can assign a product to a category and then a list of category metafields will become available on the product.
You can access them in the same way as standard metafields, but using the shopify namespace.
To see the namespace, key and return type (in this case metaobject (list)), check the relevant metafield definition here:
https://admin.shopify.com/store/<store name>/settings/custom_data/product/metafields
Example:
{% liquid
assign firstProduct = collections["all"].products.first
assign sizeMetafield = firstProduct.metafields.shopify.size.value
%}
<script>
console.log("productId", {{ firstProduct.id }});
console.log("sizeMetafield", {{ sizeMetafield | json }});
</script>
There is some confusion in these comments around options, which is perhaps because you can link these category metafields to the product options, and they would therefore display the same name, but options and category metafield values are not necessarily linked.
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025