skip to Main Content

I am trying to create an automated Commercial Invoice within Shopify, using the Liquid template language. I have everything working, except for the IMPORT/EXPORT Harmonized Codes (HS Tariff Codes) that are stored as variant meta-fields. Whenever I try to print them out using the following code, I get blanks:

{% for line_item in line_items %}
{{ line_item.variant.metafields.global_harmonized_system_code }}
{% endfor %}

Can someone help me pull these HS Codes for each product variant and print them on the Commercial Invoice using liquid to pull the meta-field?

4

Answers


  1. Your Liquid is insufficient for the task at hand.

     {{ line_item.variant.metafields.global_harmonized_system_code }}
    

    That output is not valid. It might point to a set of one or more key value pairs, so you should really iterate on that. Example:

    {% for mf in line_item.variant.metafields.global %}
      {% if mf | first == 'harmonized_system_code' %}
         <p> {{ mf | last }} how is that for some value! </p>
      {% endif %}
    {% endfor %}
    

    Something like that is more precise and will go through the variant metafields allowning you to choose which ones to print out.

    Login or Signup to reply.
  2. Global is a namespace, try :

    {{ line_item.variant.metafields.global.harmonized_system_code }}
    

    The syntax is :

    {{ your_object.metafields.namespace.key }}
    
    Login or Signup to reply.
  3. I am able to get the value using this

    {{ line_item.variant.metafields.harmonized_system_code.value }}
    
    Login or Signup to reply.
  4. {% for line_item in line_items %}
    {{ line_item.variant.metafields.harmonized_system_code.value }}
    {% endfor %}
    

    This will show the HS code

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