Conversations about creating, managing, and using metafields to store and retrieve custom data for apps and themes.
Hey guys,
I currently have:
metafield: product.custom.inclusions_optionals
inside that i have Mix reference to metaobjects: shop.metaobjects.inclusions / shop.metaobjects.optionals
I'm building a table on my products page to show inclusions and options but i'm struggling to reference the metaobjects inside the meta fields.
This code works but it gives me all incusions on all products, I need to use the meta fields inside the product to only show the inclusions related to that product.
{% for inclusion in shop.metaobjects.inclusions.values %}
<p>{{ inclusion.title.value }}</p>
{% endfor %}
Solved! Go to the solution
This is an accepted solution.
Found the issue don't need the .fields. on the value
{% if product.metafields.custom.inclusions_optionals.value != blank %}
{% for inclusion in product.metafields.custom.inclusions_optionals.value %}
<p>{{ inclusion.title.value }}</p>
{% endfor %}
{% endif %}
To display only the inclusions and options related to the current product, you need to access the metaobjects referenced in the product's metafield product.custom.inclusions_optionals. Here's how you can modify your code:
{% if product.metafields.custom.inclusions_optionals.value != blank %}
{% for inclusion in product.metafields.custom.inclusions_optionals.value %}
<p>{{ inclusion.fields.title.value }}</p>
{% endfor %}
{% endif %}
That doesn't return anything
This is an accepted solution.
Found the issue don't need the .fields. on the value
{% if product.metafields.custom.inclusions_optionals.value != blank %}
{% for inclusion in product.metafields.custom.inclusions_optionals.value %}
<p>{{ inclusion.title.value }}</p>
{% endfor %}
{% endif %}