Solved

How to display metafields on product page

moolahdigital
Shopify Partner
7 0 1

I have created a number of product metafields via Settings > Metafields:

moolahdigital_0-1627087106747.png

How do I go about displaying the value of one of these metafields on the product page itself? I've tried doing a Google search and only get results related to custom metafields made using an app.

Any help would be greatly appreciated!

Accepted Solution (1)

Developer-G
Shopify Partner
3079 604 856

This is an accepted solution.

Hello @moolahdigital ,

 

Use 

{{ product.metafields.my_fields.product_benefit_3_image_ }}

{{ product.metafields.my_fields.product_benefit_3_text_ }}

{{ product.metafields.my_fields.product_benefit_2_image_ }}

{{ product.metafields.my_fields.product_benefit_2 }}

{{ product.metafields.my_fields.product_benefit_1_image_ }}

{{ product.metafields.my_fields.product_benefit_3_text_ }}



- If helpful then please Like and Accept Solution.
- Want to modify or custom changes or bug fix on store Hire me.
- Email: guleriathakur43@gmail.com - Skype: navrocks1 ,
- Try GEMPAGES a great page builder
-Advance Search Filter

View solution in original post

Replies 12 (12)

KetanKumar
Shopify Partner
36843 3636 11978

@moolahdigital 

sorry for this issue your can do without app shopify new feature 

https://shopify.dev/api/liquid/objects/metafield

If helpful then please Like and Accept Solution.
Want to modify or custom changes on store Hire me.
- Feel free to contact me on bamaniyaketan.sky@gmail.com regarding any help
Shopify Partner | Skype : bamaniya.sky
PSD to Shopify | Shopify Design Changes | Shopify Custom Theme Development and Desing | Custom Modifications In to Shopify Theme | SEO & Digital Marketing

Developer-G
Shopify Partner
3079 604 856

This is an accepted solution.

Hello @moolahdigital ,

 

Use 

{{ product.metafields.my_fields.product_benefit_3_image_ }}

{{ product.metafields.my_fields.product_benefit_3_text_ }}

{{ product.metafields.my_fields.product_benefit_2_image_ }}

{{ product.metafields.my_fields.product_benefit_2 }}

{{ product.metafields.my_fields.product_benefit_1_image_ }}

{{ product.metafields.my_fields.product_benefit_3_text_ }}



- If helpful then please Like and Accept Solution.
- Want to modify or custom changes or bug fix on store Hire me.
- Email: guleriathakur43@gmail.com - Skype: navrocks1 ,
- Try GEMPAGES a great page builder
-Advance Search Filter
moolahdigital
Shopify Partner
7 0 1

Thank you @Developer-G - this worked perfectly!

Nalinda
Shopify Partner
33 0 12

Hi @Developer-G , Can you please let me know how this is work for product reference metafields 

eg: 

{{ item.product.metafields.product.cross_sell_product }}

Do you know how I can get the above product title , image and the handle.

 

Thank you!

emanuelepasin
Shopify Partner
6 1 3

Hi! I'm trying to achieve the same goal but with text metafields.

emanuelepasin_0-1630588150080.png

but then when I try to use them in my product-template.liquid page (see the code below)

<div class="product-highlight">
    <p>{{product.metafields.my_fields.01_product_highlights}}</p>
</div>

I get this error message:

Liquid syntax error (sections/main-product.liquid line 291): Expected id but found number in "{{product.metafields.my_fields.01_product_highlights}}"

Does anyone know how to solve this?

Thanks!

KetanKumar
Shopify Partner
36843 3636 11978

@emanuelepasin 

can you please just remove number of name for example 01 use different text

If helpful then please Like and Accept Solution.
Want to modify or custom changes on store Hire me.
- Feel free to contact me on bamaniyaketan.sky@gmail.com regarding any help
Shopify Partner | Skype : bamaniya.sky
PSD to Shopify | Shopify Design Changes | Shopify Custom Theme Development and Desing | Custom Modifications In to Shopify Theme | SEO & Digital Marketing
emanuelepasin
Shopify Partner
6 1 3

It worked!!! Super thanks 

KetanKumar
Shopify Partner
36843 3636 11978

@emanuelepasin 

it's my pleasure to help us

If helpful then please Like and Accept Solution.
Want to modify or custom changes on store Hire me.
- Feel free to contact me on bamaniyaketan.sky@gmail.com regarding any help
Shopify Partner | Skype : bamaniya.sky
PSD to Shopify | Shopify Design Changes | Shopify Custom Theme Development and Desing | Custom Modifications In to Shopify Theme | SEO & Digital Marketing
bo6
Visitor
2 0 0

Hello,
I need you help about displaying metafields under a product

I have added the following code :

{%- if product.metafields.my_fields.besoin != blank -%}
<div class="besoin-produit">{{ product.metafields.my_fields.besoin }}</div>
{%- endif -%}



But it shows me the metafield with brackets and "
Could you please help me to correct this code to show only the text metafield
Thanks in advance

Tones
Shopify Partner
8 0 6

@bo6 I was having this happen too. I found out it's because unless your metafield is a simple type like integer or string, you need to output the "value" of the metafield.

 

eg my "width" metafield is of type dimension. If you export the product you'll see it's stored as {"value":56,"unit":"cm"}

 

So this line:

 

Width: {{ product.metafields.custom.width }}

 

will display as:

Width: {"value":56,"unit":"cm"}

 

To output the values in the metafield, you need to add .value to the end of the metafield

 

Width: {{ product.metafields.custom.width.value }}

 

Width: 56 cm

 

If I wanted to display just the number from my Width metafield:

 

Width: {{ product.metafields.custom.width.value.value }}

 

Width: 56.0

 

If I wanted to display just the unit from my Width metafield:

 

Width: {{ product.metafields.custom.width.value.unit }}

 

Width: cm

 

etc.

jessica1111
Tourist
11 1 0

Hi @KetanKumar 

 

I wonder if you can help me too please?
I have been searching everywhere and asking everyoe and I can not figure this out! Nothing anyone says works for me!

 

I am using craft theme and I have created my metafields.. I have a post here but still nothing works..

 

https://community.shopify.com/c/shopify-design/craft-theme-can-t-change-the-descriptions-for-each-pr...

LitExtension
Shopify Partner
4860 1001 1135

You can follow these steps:
- Step 1: Go to products and select value for each Metafields. Refer https://i.imgur.com/WqyoeMh.png
- Step 2: Create a json template, choose the template for the products you want to create with that json template. Refer https://shopify.dev/themes/architecture/templates#json-templates
Ex: https://github.com/Shopify/dawn/blob/main/templates/product.json
- Step 3: Go to Customize and start selecting Metafields for it.
Hope it clear to you.

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify