如何在Shopify中显示元字段 [英] How to Display a Metafield in Shopify
问题描述
我们有一组产品,希望免费送货.为此,我将其重量设为= 0,并创建了重量为0磅的运输方式.
We have a group of products that we want to have FREE Shipping. In order to do so, I have made their weight =0 and created a weight based shipping for 0lbs.
这样,运输就通过了购物车.但是...我想在产品页面上显示实际重量.
That way the shipping passes through the cart. But...I would like to display the actual weight on the product page.
我已经为运输重量创建了一个元字段,我正试图将该值调用到产品页面,但没有任何运气......
I have created a metafield for the shipping weight, and I am trying to call that value to the product page, but not having any luck......
这是我正在尝试的代码....
Here is what I am trying for code....
//------SHIPPING WEIGHT-------------------------//
{% if product.vendor == 'American Chains' %}
$('.wt').text((variant.ShippingWeight)+'lb');
// {{ variant.metafields.ShippingWeight.shipping_weight }}
{% else %}
$('.wt').text(parseInt(variant.weight * 0.0022046, 10) + 'lb');
{% endif %}
//------SHIPPING WEIGHT-------------------------//
感谢对此的任何帮助或指导.
Thanks for any help or direction on this one.
推荐答案
在 Product.liquid 您只能访问该产品.如果要访问特定的产品变式,则必须遍历产品变式.在循环中,您可以访问 metafields 作为变体.
In Product.liquid you only have access to the Product. If you want to access a specific Product Variant you have to loop through the Product Variants. Within the loop you have access to the metafields for a variant.
{% for variant in product.variants %}
// to display the variant metafields use {{resource.metafields.namespace.key}}
{{ variant.metafields.ShippingWeight.shipping_weight }}
{% endfor %}
这篇关于如何在Shopify中显示元字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!