Solved

Dawn Theme - Show Product Metafields in the Collection Grids

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 }}

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 Solution (1)
willbeing
Shopify Partner
8 2 1

This is an accepted solution.

The goal is to display metafield data for each product in a collection page. This data is not immediately available. The following solution 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 2 (2)

BSS-Commerce
Shopify Expert
3398 450 503

Hi @willbeing ,

To better know whether your product section has access to metafields or not, inspect your product in the card-product.liquid file.

{{ product | json }}

 If your product is null. It could be because you placed the code in the wrong file or because the name of the product variable is wrong.

If our suggestions are useful, please let us know by giving it a like or marking it as a solution.

For B2B solutions and custom pricing, check out B2B Solution & Custom Pricing |
For adding product labels/badges, visit Product Labels by BSS

BSS Commerce - Shopify Apps & Store Development Service Provider

Hire a Shopify expert | Shopify Plus Store Development

willbeing
Shopify Partner
8 2 1

This is an accepted solution.

The goal is to display metafield data for each product in a collection page. This data is not immediately available. The following solution 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 %}