Customize Your Shopify Invoice Template With Liquid
A practical introduction to editing an invoice template in Liquid and CSS: printing order data, conditions, loops, metafields and print-friendly styles.
PDF invoices and estimates for Shopify: seven designed themes, gap-free numbering, automatic emails and customer downloads. Free for 50 documents a month.
If you have edited a Shopify theme, you already know Liquid. Invoice templates use the same language to print order data, which means you can customise a Shopify invoice template far beyond what any settings panel offers: a message for wholesale customers, a column from a product metafield, a bank-transfer note only on unpaid invoices. A handful of Liquid tags and a little CSS for print cover nearly all of it.
Where the Code Lives
In Ultimate Invoice Printer, open Templates, choose Customize on a theme, and switch the Template Editor to Code. A template is a small set of files:
Layout: the page itself, which places every block in order.
Head: the page's metadata and the rules that apply your Template Settings.
One file per block: shop details, addresses, line items, totals, notes and so on.
CSS: the stylesheet.
The preview beside the code re-renders half a second after you stop typing.
Code mode: Liquid on the left, the live invoice on the right. Click or tap the image to see it full size.
Liquid in Five Minutes
Print a Value
Invoice {{ order.invoice_number }} for order {{ order.name }}
{{ billing_address.name }}, {{ billing_address.city }}
Total: {{ total }}
Amounts arrive already formatted in the document's currency.
Show Something Only When It Applies
{% if order.note != blank %}
<p class="note">{{ order.note }}</p>
{% endif %}
{% if order.has_payment %}
Paid on {{ order.payment_date }}
{% elsif has_amount_due %}
Please pay {{ amount_due }} by {{ order.due_date }}.
{% endif %}
Metafields hold the data Shopify has no field for: a warranty period, a care instruction, a harmonised code, a customer's account number. Once you select them in Settings → Metafields, they are available in the template:
{% for item in line_items %}
{{ item.title }}
{% if item.product.metafields.custom.warranty != blank %}
Warranty: {{ item.product.metafields.custom.warranty }}
{% endif %}
{% endfor %}
Account no. {{ customer.metafields.custom.account_number }}
JSON metafields can be read with the parse_json filter. Metafields need the Enterprise plan; see Using Metafields in Templates.
Add Code Without Touching the Layout
You do not have to edit the template's files for a small addition. In Preview mode, add a Custom Liquid block anywhere on the invoice and write its code in the block's panel; each block keeps its own code. For plain text, a Free Text block needs no code at all. See Custom Blocks.
CSS for Printable Invoices
Set colours and fonts in Template Settings; they are applied after your stylesheet and win over it.
Use relative units (em, rem, %), so the page fits A4 and whatever paper the browser prints on.
Web fonts load with an @import url(…); at the very top of the CSS.
Safe by Design
A Liquid mistake shows an error banner with the line and column, the preview keeps the last good version, and Save stays disabled until the error is fixed; the app checks the template again when you save or publish, so a broken template never reaches a customer. Customer-entered data is made safe for HTML before the template sees it. Scripts in templates do not run, in the preview or in the PDF, so build with Liquid, HTML and CSS.