I want to create some custom fields into the Shopify Admin application. I read about metafields in the Shopify API documentation. But somehow was not able to understand how to use metafields and where it will get reflected.
I tried to add metafields to products resource and the API call was successful. I was expecting that the new fields which I added would reflect on the Add Products page. But unfortunately it did not appear.
So can anyone please help me understand how to go about these metafields?
Hi, you can’t view metafields directly. But you can access them using liquid variables.
For example, you might want to add additional information to orders or products such as hotlinks which should be displayed to the customer on their account page. You can edit the customer.account template and display those metafields, e.g.:
{% for line_item in order.line_items %}
{% if line_item.fulfillment and line_item.product.metafields.yournamespace.yourkey %}
{% for metafield in line_item.product.metafields.yournamespace.yourkey %}
<tr>
<td colspan="5">
<a href="{{ metafield.href }}" target="_blank">
{{ metafield.href_text }}
</a>
</td>
</tr>
{% endfor %}
{% endif %}
{% endfor %}
Once you’ve uploaded the product with metafields via the API you will need to use or create an app to view/edit them (see my previous link for such an app).