user2120605
user2120605

Reputation: 31

How to Display a Metafield in Shopify

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.

Upvotes: 3

Views: 19433

Answers (5)

sabithkumar
sabithkumar

Reputation: 412

In metafield section, shopify show's shortcode. For below screenshot the code is

{{product.metafields.custom.theme_color}}

enter image description here

Upvotes: 0

Manmeet Kaur
Manmeet Kaur

Reputation: 49

        ------------------------------
         {{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>

Upvotes: 1

YoJey Thilipan
YoJey Thilipan

Reputation: 687

  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

Upvotes: 0

Siddhu
Siddhu

Reputation: 41

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

Upvotes: 4

hjblok
hjblok

Reputation: 2966

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

Upvotes: 4

Related Questions