How to retrieve Metafields mixed reference using liquid?

Solved

How to retrieve Metafields mixed reference using liquid?

dankron
Shopify Partner
22 1 8

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 %}
Accepted Solution (1)
dankron
Shopify Partner
22 1 8

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 %}

View solution in original post

Replies 3 (3)

SomeUsernameHe
Shopify Partner
515 57 109

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 %}
Have I helped? Consider putting coffee in my mouth!
Buy Me a Coffee
dankron
Shopify Partner
22 1 8

That doesn't return anything

dankron
Shopify Partner
22 1 8

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 %}