Cannot fetch metafield values

The metafield is type Product (list of products).
I have tried {% for product in product.metafields.custom.upsell_styled_with.values %} (plural) too, but still no output.
Here are 3 examples of different outputs. Actually, first 2 have outputs, but the 3rd doesn’t even run the loop, as there is no p tag in third case:

Output:

Hi @Balvan

I think the reason you don’t see any output in your for loop, because you are trying to iterate through a single value.

Your variable styled_with_products is not an abject.

by doing this

{% assign styled_with_products = product.metafields.custom.upsell_styled_with.value

you just say let’s store a single value in styled_with_products.

Does it make sense?

2 Likes

I think @Eugene_Kasimov is right.

This works for me:

{% for product in product.metafields.custom.bundle_products.value %}
   ...{{ product.title }}...
{%- endfor -%}

which is identical - just without assigning it first.

@curzey @Eugene_Kasimov
The client has actually chosen archived products in the metafield :sweat: so that was the issue.
Thank you for your suggestions!

2 Likes

That’s a struggle.

Archived products and b2b catalogs where not all customers has access to specific products.