How to Display a Metafield in Shopify

2019-07-21 10:19发布

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.

4条回答
闹够了就滚
2楼-- · 2019-07-21 10:44
  1. Meta fields are created by using ( metafields or shopify FD ) shopify app for products edit page

  2. Then enter the following values in form fields (Namespace,Key,Value)

  3. After entering values,you can retrive values like following code..,

Namespace = metafield_values,

Key= color,

Value= red,

{% assign value = product.metafields.metafield_values%}

<p>{{ value.color }}</p>

output: red

查看更多
Animai°情兽
3楼-- · 2019-07-21 10:48
        ------------------------------
         {{metafields.namespace.key}}
        ------------------------------

Namespace = prod_video,

{{ product.metafields.prod_video.prod_video }}

{{ collection.metafields.prod_video.prod_video }}

---------metafield loop with same namespace & different key------------

<div class="prod_add_img">  
    {% for collection in product.collections %}
        {% for field in collection.metafields.additional_images %}
            <img src="{{ field | last | asset_url }}"> 
        {% endfor %}
    {% endfor %}
</div>
查看更多
虎瘦雄心在
4楼-- · 2019-07-21 10:59

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 %}
查看更多
趁早两清
5楼-- · 2019-07-21 11:06

http://docs.shopify.com/themes/liquid-documentation/objects/metafield go threw with this link simple...

{% for field in product.metafields.instructions %}
{{ field | first }}: {{ field | last }}
{% endfor %}
查看更多
登录 后发表回答