Custom Liquid blocks for printed receipts
You can use a custom Liquid block to add your own content to the header or footer of a printed receipt, such as order details, customer information, product properties, metafields, and barcodes.
Custom Liquid blocks render on printed receipts for completed online and Point of Sale orders. They don't render for orders that use offline checkout.
You can add a custom Liquid block from the receipt visual editor in your Shopify admin. The values that you reference are pulled from the receipt's data when the receipt is printed. For example, the following Liquid code adds the order note to the receipt when a note exists:
{% if order.note %}
<p>Order note: {{ order.note }}</p>
{% endif %}On this page
Liquid syntax rules
Review the following syntax rules before you build a custom Liquid block:
- Variable names use lowercase letters and underscores, a format known as snake_case. For example, use
order.total_price,order.customer.display_name, andorder.line_items. - Money values are plain numbers. Format them with the
moneyfilter, such as{{ order.total_price | money }}. - Guard optional values with an
ifstatement so that you don't print an empty line, such as{% if order.customer.email %}{{ order.customer.email }}{% endif %}. - Loop over lists with a
forstatement, such as{% for item in order.line_items %} ... {% endfor %}. - Some Liquid tags aren't supported. You can't use
assign,capture,include,render,raw,increment, ordecrement. If your block uses an unsupported tag, then your receipt won't save and you'll see an error. - A custom Liquid block can contain up to 50 KB of code.
HTML and CSS
You can use basic HTML in a custom Liquid block to structure your content, such as <p>, <br>, <strong>, <em>, headings, lists, and links. Your content uses the receipt's existing fonts and sizes.
You can't use CSS to change how a receipt looks. <style> blocks and style attributes aren't supported, so that a custom Liquid block can't restyle or hide content elsewhere on the receipt. <script> tags, event handlers such as onclick, and javascript: links aren't supported either.
If your block contains unsupported HTML, then your receipt won't save and you'll see an error. Remove the unsupported HTML, and then save again.
Variables and objects
A custom Liquid block can reference the following objects and variables. Some values aren't on the default receipt, so a custom Liquid block is one way to add them.
Top-level variables
The following top-level variables are available in a custom Liquid block.
| Variable | Description |
|---|---|
order | The order being printed. |
shop | The store. |
location | The retail location. |
settings | The receipt's display settings, which are the toggles configured in the editor. |
purchased_gift_cards | The gift cards bought on this order. |
staff_member_description | The attributed staff member, when staff display is turned on. |
locale | The receipt locale, such as en. |
is_pickup | Whether the order is a pickup order. |
pickup_location | The pickup location, when applicable. |
Order object
| Property | Description |
|---|---|
name | The order name, such as #1001. |
created_at |
The order timestamp. Use with the date filter.
|
note | The order note. |
subtotal_price |
The subtotal. Format with the money filter.
|
total_price |
The total. Format with the money filter.
|
shipping_price |
The shipping charged. Format with the money filter.
|
total_tip_received |
The tip total. Format with the money filter.
|
balance_due |
The amount still owing. Format with the money filter.
|
change_due |
The change given. Format with the money filter.
|
taxes_included | Whether tax is included in the prices. |
receipt_number | The receipt number. |
barcode_content | The content to encode in a barcode. |
qr_code_content |
The content to encode in a QR code. Use with the qrcode filter.
|
line_items | The purchased items. Each item's properties are listed in the order line item object. |
transactions | The payments. Each payment's properties are listed in the transaction object. |
discounts | The order-level discounts. Each discount's properties are listed in the discount object. |
tax_lines | The tax lines. Each tax line's properties are listed in the tax line object. |
refunds | The refunds on the order. |
shipping_address | The shipping address. Address properties are listed in the address object. |
customer | The customer's details, listed in the customer object. |
metafields | The order metafields. |
Customer object
The order.customer object contains the customer's details.
| Property | Description |
|---|---|
display_name | The customer's display name. |
first_name | The customer's first name. |
last_name | The customer's last name. |
| The customer's email address. | |
phone | The customer's phone number. |
default_address | The customer's default address. |
metafields | The customer metafields. |
Order line item object
Each item in order.line_items contains the following properties.
| Property | Description |
|---|---|
name | The product or line name. |
variant_title | The variant, such as Large / Blue. |
sku | The SKU. |
vendor | The vendor. |
quantity | The quantity. |
price |
The unit price. Format with the money filter.
|
total_price |
The line total. Format with the money filter.
|
discounted_total_price |
The line total after discounts. Format with the money filter.
|
discounted_unit_price |
The per-unit price after discounts. Format with the money filter.
|
discounts | The discounts applied to the line. |
selling_plan_name | The subscription or selling plan name, if any. |
staff_member_description | The staff member attributed to the line. |
custom_attributes | The line item properties, accessed by key. |
product_metafields | The product metafields, accessed by key. |
variant_metafields | The variant metafields, accessed by key. |
Transaction object
Each payment in order.transactions contains the following properties. Store credit spent on the order is listed as a payment named Store credit. The customer's remaining store credit balance isn't available as a variable.
| Property | Description |
|---|---|
name | The payment name, such as Visa, cash, or store credit. |
payment_type | The payment type code. |
amount |
The amount. Format with the money filter.
|
kind | The transaction kind. |
status | The transaction status. |
credit_card_number | The masked card number, when applicable. |
created_at | The transaction timestamp. |
additional_details | Extra payment detail lines. |
Shop object
The shop object contains the store's details.
| Property | Description |
|---|---|
name | The store name. |
domain | The store domain. |
currency | The store currency. |
id | The store ID. |
Location object
The location object contains the retail location's details.
| Property | Description |
|---|---|
name | The location name. |
address1 | The first address line. |
address2 | The second address line. |
city | The city. |
province | The province or state. |
province_code | The province or state code. |
zip | The ZIP or postal code. |
country | The country. |
phone | The phone number. |
metafields | The location metafields. |
Address object
An address, such as order.shipping_address or order.customer.default_address, contains the following properties.
| Property | Description |
|---|---|
company | The company name. |
name | The recipient's name. |
address1 | The first address line. |
address2 | The second address line. |
city | The city. |
province | The province or state. |
province_code | The province or state code. |
zip | The ZIP or postal code. |
country | The country. |
country_code | The country code. |
phone | The phone number. |
Discount object
Each discount in order.discounts or item.discounts contains the following properties.
| Property | Description |
|---|---|
description | The discount description. |
amount | The discount amount. Format with the money filter. |
percentage | The discount percentage. |
Tax line object
Each tax line in order.tax_lines contains the following properties.
| Property | Description |
|---|---|
title | The tax title. |
rate | The tax rate as a decimal. |
rate_percentage | The tax rate as a percentage. |
price | The tax amount. Format with the money filter. |
taxable_amount | The amount subject to tax. Format with the money filter. |
Gift card object
Each gift card in purchased_gift_cards contains the following properties.
| Property | Description |
|---|---|
code | The gift card code. |
masked_code | The masked gift card code. |
balance | The gift card balance. Format with the money filter. |
created_at | The gift card timestamp. |
qr_code_content | The content to encode in a QR code. |
Metafields and properties
Metafields and line item properties come in two shapes.
Line item metafields and properties are keyed. Access a value directly by its key:
{{ item.product_metafields.care_instructions }}
{{ item.custom_attributes.engraving }}Order and customer metafields are lists. Loop over them:
{% for m in order.metafields %}
{{ m.namespace }}.{{ m.key }}: {{ m.value }}
{% endfor %}Keys are normalized to snake_case. A key such as Care Instructions or careInstructions is accessed as care_instructions. Always reference keyed values in lowercase with underscores.
The availability of order and customer metafields depends on those metafields existing on the record.
Liquid filters
You can use filters to format the information in your custom Liquid block. To apply a filter, add a pipe character, |, and then the filter inside the Liquid output, such as {{ order.total_price | money }}.
Standard Liquid filters also work. To learn more about Liquid filters, refer to the Filters reference.
| Filter | Example | Description |
|---|---|---|
money | {{ order.total_price | money }} | Formats an amount in the receipt currency. |
date | {{ order.created_at | date: '%B %e, %Y' }} | Formats a date or time. |
percent | {{ tax_line.rate | percent }} | Formats a decimal as a percentage, such as 0.2 as 20%. |
t | {{ 'receipt.total' | t }} | Returns a translated label. |
barcode | {{ order.barcode_content | barcode }} | Renders a barcode. |
qrcode | {{ order.qr_code_content | qrcode }} | Renders a QR code. |
Examples of custom Liquid blocks
The following examples add content that isn't on a default printed receipt template.
To add the order note when one exists, use the following Liquid:
{% if order.note %}<p>Note: {{ order.note }}</p>{% endif %}To add the SKU next to each item, use the following Liquid:
{% for item in order.line_items %}
<p>{{ item.name }} — {{ item.sku }} ×{{ item.quantity }}</p>
{% endfor %}To add a line item property, such as an engraving, use the following Liquid:
{% for item in order.line_items %}
{% if item.custom_attributes.engraving %}
<p>{{ item.name }} — Engraving: {{ item.custom_attributes.engraving }}</p>
{% endif %}
{% endfor %}To add a product metafield, such as care instructions, use the following Liquid:
{% for item in order.line_items %}
{% if item.product_metafields.care_instructions %}
<p>{{ item.name }}: {{ item.product_metafields.care_instructions }}</p>
{% endif %}
{% endfor %}To add a customer metafield, use the following Liquid:
{% for m in order.customer.metafields %}
{% if m.key == 'loyalty_tier' %}<p>Loyalty tier: {{ m.value }}</p>{% endif %}
{% endfor %}To add a QR code that links to the order, use the following Liquid:
{{ order.qr_code_content | qrcode }}