Dawn Theme - Show Product Metafields in the Collection Grids

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 Partner
3477 464 552

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, marking it as a solution, or donating here .


B2B Solution & Custom Pricing | Product Labels by BSS


Need help from our expert? Kindly share your request with us via community@bsscommerce.com


BSS Commerce - Full-service eCommerce Agency
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 %}