Liquid, JavaScript, themes, sales channels
Join us March 21 for an AMA on planning your 2023 marketing budget with 2H Media co-owners, Matt and Aron
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 %}
<div class="badges-wrapper">
{% if itemType.available %}
{% if itemType.compare_at_price_min > itemType.price_min %}
<span class="badge badge-sale">{{ 'products.product.on_sale' | t }}</span>
{% endif %}
{% capture new-tag %}{{ 'products.product.new' | t }}{% endcapture %}
{% if itemType.tags contains new-tag %}
<span class="badge badge-new">{{ product.metafields.custom.plastic_pieces }}</span>
{% endif %}
{% else %}
<span class="badge badge-soldout">{{ 'products.product.sold_out' | t }}</span>
{% endif %}
</div>
Solved! Go to the solution
This is an accepted solution.
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 }}
This is an accepted solution.
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 }}
User | RANK |
---|---|
21 | |
18 | |
13 | |
12 | |
8 |
Thanks to all Community members that participated in our inaugural 2 week AMA on the new E...
By Jacqui Mar 10, 2023Upskill and stand out with the new Shopify Foundations Certification program
By SarahF_Shopify Mar 6, 2023One of the key components to running a successful online business is having clear and co...
By Ollie Mar 6, 2023