Add Metafields Through API

I want to add metafields as specifications for the products in the store.

I added metafields as below:

namespace: "specs", 
key : [name of spec (ex. screen resolution)],
value: [value of screen resolution]

When I did this I was able to display the specifications in the product page as:

{% for metafield in product.metafields.specs %}
<p>{{ metafield.first }}: {{ metafield.last }}</p>
{% endfor %}

but I was not able to use them for filtering because they were not defined. And I was unable to define them through the Shopify Admin because they had specials chars (spaces).

Then I tried to add the key as a handle, with dashed instead of spaces and no more brackets, and added one more field to the metafields as description – that was the name of the spec with spaces and so on – however I can’t display the metafield.description value.

Any idea how can I add the metafields already defined, or to display the description?

Leave a Comment