Using Timber and Shopify, how can I add meta fields on the ajax mini cart of timber?

三世轮回 提交于 2021-01-07 01:21:02

问题


I’m using Timber in a Shopify theme.

I would look to add meta fields of the product on the cart. Cart screenshot here

The metafields are showing on product i would like to show that on Ajax mini cart too. product page screenshot

js code here

Let me know if its possible.


回答1:


Here are a few examples on how you may access a product's metafields.

In the cart page though, because you don't have a direct access to the product object, you should first get access to the product object via the [line_item][2] object to be able to access the metafields, example:

{% for item in cart.items %}
  {{ item.product.metafields.key }}
{% endfor %}

And that should do the trick!



来源:https://stackoverflow.com/questions/65108306/using-timber-and-shopify-how-can-i-add-meta-fields-on-the-ajax-mini-cart-of-tim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!