skip to Main Content

I am using metafields editor to display some additional information in the Shopify store. I need help in displaying the output of the below product variant metafields in Shopify product page. What code do I need to add into the product.liquid file? Do I also need to have a JavaScript snippet?

Product description metafield for product variants:

namespace: variantdescription
key: Product Description
value: This is product description for variant A
value_type: string

Product delivery metafield for product variants:

namespace: variantdelivery
key: Delivery Time
value: This is delivery time for variant A
value_type: string

2

Answers


  1. You can get the metafield value with this code:

    product.metafields.NAMESPACE.KEY
    

    The code that you have to use for product description will be something like this:

    {%- if product.metafields.variantdescription.product_description != blank -%}
    
        {{ product.metafields.variantdescription.product_description }}
    
    {%- endif -%}
    

    It will be like this for the Delivery time:

    {%- if product.metafields.variantdelivery.delivery_time != blank -%}
    
        {{ product.metafields.variantdelivery.delivery_time }}
    
    {%- endif -%}
    

    Here is the information about how to use metafields in liquid.
    https://help.shopify.com/en/themes/liquid/objects/metafield

    JavaScript is not needed.

    Login or Signup to reply.
  2. Get Description of current variant:

    {% assign description = current_variant.metafields.variantdescription%}
    {% assign key =  current_variant.sku  %}
    {% assign description = description[key] %}
    

    Likewise for product delivery

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search