Using Metafields in Templates
Print the metafields you selected in Settings → Metafields: in the Metafields block, under each line item, or anywhere in Liquid, including JSON values.
Metafields reach documents on Enterprise. First pick them in Settings → Metafields; only the metafields you selected there (and the ones a template's blocks print) are fetched for each document.
Three Ways to Print Them
- The Metafields block: order, customer and shop metafields as "Label: value" rows. Add it with + in Preview mode; see Custom Blocks.
- The Line Items block: Show Product Metafields and Show Variant Metafields print the chosen product and variant metafields under each line. A custom line item with no product prints none.
- Liquid, in Code mode or a Custom Liquid block, wherever you like.
Liquid Paths
{{ order.metafields.custom.po_number }}
{{ customer.metafields.custom.account_code }}
{{ shop.metafields.custom.bank_details }}
{% for item in line_items %}
{{ item.product.metafields.custom.warranty }}
{{ item.variant.metafields.custom.colour_code }}
{% endfor %}Replace custom.po_number with your metafield's namespace and key. Product and variant metafields are read through each line, using the loop's own name (item in the built-in themes). On estimates, order.metafields reads the Draft Order metafields you selected (and the ones a Metafields block picks), never the Order list. A metafield that is not set on the order prints nothing, so wrap a label in {% if … != blank %}.
How Each Type Prints
Values arrive as Shopify stores them, as text. Text, number and URL metafields print as they are; dates print as 2026-05-12 (reformat with | date: "%b %d, %Y", which writes English month names and reads a date and time in UTC); money, measurements, ratings, JSON and lists are JSON text you can read with parse_json. The built-in Metafields and Line Items blocks print money, measurement, rating and link values readably for you, with | metafield_value: "product", "custom", "price" (the owner, namespace and key); every other value comes back as it is. Rich text and references print Shopify's raw data, not content. The full list is in Metafields.
JSON Values With parse_json
{% assign spec = item.product.metafields.custom.spec | parse_json %}
{{ spec.dimensions.width }} × {{ spec.dimensions.height }} cm
{% assign sizes = item.product.metafields.custom.sizes | parse_json %}
{% for size in sizes %}
{{ size }}{% unless forloop.last %}, {% endunless %}
{% endfor %}
{% assign price = order.metafields.custom.deposit | parse_json %}
{{ price.amount }} {{ price.currency_code }}parse_json returns nothing for an empty or malformed value, so the document never breaks.
Unstructured Metafields
A metafield written by another app or by the Admin API often has no definition in Shopify, so it never appears in the picker. Add it in Settings → Metafields with + Add Manually by its Namespace and Key. It is marked Unstructured and prints exactly like a defined one, at the same Liquid path.
Kept Values
A metafield set to Keep First Value in Settings → Metafields prints, at the same Liquid path, the value kept when the document was first made — in every later PDF and in every preview of that order, the Template Editor's picked order included. The block pickers and the Liquid reference mark such a metafield Keeps first value. A metafield a block prints without selecting it in Settings always prints the latest value.
Was this guide missing something? Tell us and we will fix it.
Contact Us