Re: Display Product Metafield Inside Collection | Dawn Theme

Solved

Display Product Metafield Inside Collection | Dawn Theme

willbeing
Shopify Partner
8 2 1

The goal is to display product metafields on the collection pages, yet calling the following lines of code inside card-product.liquid returns null/blank: 

 

{% if product.metafields.custom.width %}
  <p>{{ product.metafields.custom.width }}</p>
{% endif %}
{{ product.metafields | json }}

This seems to be an issue with scope. How does one enable collections to access product metafields in the Dawn theme?

 

Below are images of the metafields for namespace info.

 

Screenshot 2023-12-18 at 12.46.48.pngScreenshot 2023-12-18 at 12.46.53.png

Accepted Solutions (2)

Made4uo-Ribe
Shopify Partner
6827 1629 2007

This is an accepted solution.

Hi @willbeing 

 

You need to use a forloop. See example below

 

 

{% for product in collection.products %}
{% if product.metafields.custom.width.value %}
  <p>{{ product.metafields.custom.width.value }}</p>
{% endif %}
{% endfor %}

 

 

 

Please don't forget to Like and Mark Solution to the post that helped you. Thanks!

If this fixed your issue Likes and Accept as Solution is highly appreciated. Coffee tips fuels my dedication.
Get EXPERIENCED Shopify developers at affordable rates—visit Made4Uo.com for quick quote!
Do not lost your Shopify store! Get FREE trial with ✔️ Rewind Backup: Automatic, reliable, stress-free.
Need THEME UPDATES but has custom codes? No worries, contact us for affordable price.

View solution in original post

willbeing
Shopify Partner
8 2 1

This is an accepted solution.

No need to respond, @Made4uo-Ribe - looks like comparing product.id to card.product.id works:

{% for product in collection.products %}
  {% if product.metafields.custom.width.value and product.id == card_product.id %}
    <p>{{ product.metafields.custom.width.value }}</p>
  {% endif %}
{% endfor %}

 

View solution in original post

Replies 3 (3)

Made4uo-Ribe
Shopify Partner
6827 1629 2007

This is an accepted solution.

Hi @willbeing 

 

You need to use a forloop. See example below

 

 

{% for product in collection.products %}
{% if product.metafields.custom.width.value %}
  <p>{{ product.metafields.custom.width.value }}</p>
{% endif %}
{% endfor %}

 

 

 

Please don't forget to Like and Mark Solution to the post that helped you. Thanks!

If this fixed your issue Likes and Accept as Solution is highly appreciated. Coffee tips fuels my dedication.
Get EXPERIENCED Shopify developers at affordable rates—visit Made4Uo.com for quick quote!
Do not lost your Shopify store! Get FREE trial with ✔️ Rewind Backup: Automatic, reliable, stress-free.
Need THEME UPDATES but has custom codes? No worries, contact us for affordable price.
willbeing
Shopify Partner
8 2 1

Thank you, @Made4uo-Ribe. When used inside card-product.liquid, this lists the width of every product in the collection within each card. What condition should be added to list only the width for that card?

 

Screenshot 2023-12-19 at 08.41.30.png

willbeing
Shopify Partner
8 2 1

This is an accepted solution.

No need to respond, @Made4uo-Ribe - looks like comparing product.id to card.product.id works:

{% for product in collection.products %}
  {% if product.metafields.custom.width.value and product.id == card_product.id %}
    <p>{{ product.metafields.custom.width.value }}</p>
  {% endif %}
{% endfor %}