Metafield on product card in collection page

Topic summary

A user needed help displaying a metafield value below the product price on collection pages. The initial issue was that the metafield appeared as [\

Summarized with AI on November 13. AI used: claude-sonnet-4-5-20250929.

Hello.

How do i add Metafield under price in collection page?

I have this code:

but then it looks like this: [“5G”] instead of just 5G

I have tried with card_ in front, but then nothing comes up at all..

Can anyone help me? :slightly_smiling_face:

The issue you’re encountering with the display of your Metafield value as [“5G”] instead of just 5G suggests that the Metafield data is being stored and retrieved as an array, not as a simple text string. This is why you see the square brackets.

You can adjust your code like this:

{{ product.metafields.custom.forbindelse[0] }}

That didnt work :disappointed_face:

If the Metafield is indeed returning a string that looks like an array, you can use string manipulation to remove the brackets and quotes.

{% assign metafield_value = product.metafields.custom.forbindelse | remove: '[' | remove: ']' | remove: '"' %}
{{ metafield_value }}

I Think it because its a list of values, and not a value.

just tried with one a value, and thats seems to work.

But thats works to, do you know how i can add a border around with border-radius?

1 Like

You should be able to wrap it in a div and give that div a border and radius.


  {% assign metafield_value = product.metafields.custom.forbindelse | remove: '[' | remove: ']' | remove: '"' %}
  {{ metafield_value }}


That worked.

But now its on all my collection pages, can you do it so its only on one collection?

You can use {% if collection.handle == ‘test’ %} to only show the badge on certain collections. Just replace ‘test’ with your correct collection handle.

{% if collection.handle == 'test' %}

   {% assign metafield_value = product.metafields.custom.forbindelse | remove: '[' | remove: ']' | remove: '"' %} {{ metafield_value }} 

{% endif %}

Worked like a charm :grinning_face_with_smiling_eyes:

You been so helpful :grinning_face_with_smiling_eyes:

1 Like

Awesome! I am super glad I could help!

If you need to show this on other collections you can always use something like this:

{% assign collection_handles = 'test1,test2,test3' | split: ',' %}

{% if collection_handles contains collection.handle %}
  Hello
{% endif %}

If you have any other questions, feel free to ask!

Happy Coding!