Product metafield not showing on product badge

Hi there,

I’m trying to create a custom product badge, which pulls in a metafield value if a specific tag (for now just hijacking the “new” tag) is added to the product. The {{ product.metafields.custom.plastic_pieces }} works when I test it on a product page, (and have also tried prefixing with “products.” like the other badges) so I’m guessing it’s something else. Please help!

{% comment %}
@param itemType {Product}
  Product to apply badge to.
{% endcomment %}

  {% if itemType.available %}
    {% if itemType.compare_at_price_min > itemType.price_min %}
      {{ 'products.product.on_sale' | t }}
    {% endif %}

    {% capture new-tag %}{{ 'products.product.new' | t }}{% endcapture %}
    {% if itemType.tags contains new-tag %}
  	  {{ product.metafields.custom.plastic_pieces }}
    {% endif %}
  {% else %}
    {{ 'products.product.sold_out' | t }}
  {% endif %}

After battling with this today, I figured it out! Adding here in case anyone else needs it in the future. It needed to be “itemType.metafields” instead of “product.metafields”. Now it’s like the below, it works!

{{ itemType.metafields.custom.plastic_pieces }}
1 Like