I need help adding a metafield to my product page

Solved
jessica-b
Tourist
7 1 2

Hi there -

I've used Custom Fields for the last year to add metafields to my site. Now I'm trying Shopify's built in metafields, but I'm having trouble with the code. My product template is very customized, so I need to do this manually. 

1) I added a new metafield called new_tab in Shopify. 

2) I typed the word New! into that field on a product page. 

3) Now I need to display the field... but I'm stuck. The below code isn't working. What have I got wrong? 

{% if product.metafields["new_tab"] != blank %}
<div class="sale_banner_product">
{{ product.metafields["new_tab"] }}
</div>
{% endif %}

 

 

 

0 Likes
jessica-b
Tourist
7 1 2

This is an accepted solution.

I realized my main mistake... I hadn't included the full namespace and key... but there were others. Here's the working code.

 

{% if product.metafields.my_fields.new_tab != blank %}
<div class="sale_banner_product">
{{ product.metafields.my_fields.new_tab }}
</div>
{% endif %}

 




0 Likes