Solved

Get product reference from metafields

Nalinda
Shopify Partner
33 0 12

Hi all,

I'm trying to use the new product meta-field to add cross-sell products to my cart.

https://help.shopify.com/en/manual/metafields

How can I get the product into the liquid. I have added the below code:

{{ item.product.metafields.product.cross_sell_product_1 }}

 It is returning string like this : gid://shopify/Product/xxxxxxxxxxxxxxx

https://shopify.dev/apps/metafields/definitions/types

How I can get the product from this with liquid, So I can show the product name, image, name and varients.

 

Thank you! 

Accepted Solution (1)

LitExtension
Shopify Partner
4860 1001 1132

This is an accepted solution.

You can use code:
{% assign productMetafields = all_products[item.product.metafields.product.cross_sell_product_1] %}
Then you can display it with variable productMetafields.
Hope it helps!

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify

View solution in original post

Replies 6 (6)

LitExtension
Shopify Partner
4860 1001 1132

This is an accepted solution.

You can use code:
{% assign productMetafields = all_products[item.product.metafields.product.cross_sell_product_1] %}
Then you can display it with variable productMetafields.
Hope it helps!

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify
hellovlad
Shopify Partner
1 0 0

It doesn't work for me. When I choose a product in the metafield as a related product, the value of the variable you are assigning here is blank. 

[[object]].metafields.[[namespace]].[[key]]

this returns nothing.  

PedroInfoSoft
Shopify Partner
2 0 0

In the latest for select multiple product reference, you can show like this :

{% for refer_product in item.product.metafields.product.multiple_reference.value %}
   {% assign productName = refer_product.title %}

   {% assign productHandle = refer_product.handle %}
{% endfor %}

for single meta title use like:

  {% assign refer_product = item.product.metafields.product.single_reference.value %}

   {% assign productName = refer_product.title %}

   {% assign productHandle = refer_product.handle %}

 

More support, you can contact pedroinfosoft@gmail.com

 

Shivamsinh
Visitor
2 0 0

how to add product reference metafield in theme? here i done some step after what to do i can not know help me to solve out.1.png2.png

PedroInfoSoft
Shopify Partner
2 0 0

check above code

laurafischer
Shopify Partner
1 0 1

 

{% assign cross_sell_product =  item.product.metafields.product.cross_sell_product_1.value %}  

Then you can use `cross_sell_product` as a product object in liquid.