I’m trying to fetch the assigned products to a product in the metafields. The content type is "Product (List)" (not sure if this is the correct type but it seems so)
I tried to render them through this liquid code:
<section class="product-list">
<div>
{% for bundle_product in product.metafields.custom.bundle %}
{% include 'single-product-card', bundle_product %}
{% endfor %}
</div>
</section>
However, nothing is being displayed. I logged the output of product.metafields.custom.bundle
and it returned this:
['gid://shopify/Product/7580521365703', 'gid://shopify/Product/7510314975431']
How should I properly loop on them?
2
Answers
{% if article.metafields.custom.mentioned_products %}
{% assign mentionproduct = article.metafields.custom.mentioned_products.value %}
{% endif %}
The answer above looks correct but I thought I would add a bit of explanation. The thing to do is to assign the metafield to a variable but to do that you need to use the .value property of the metafiled.
So try changing your original code this:
To this: