Getting startedEmail the invoice as PDF when an order is paid

Email the invoice as PDF when an order is paid

Copy page

A Shopify Flow workflow that generates the invoice with Workflow Documents when an order is paid and emails it to the customer as a PDF attachment with Workflow Transactional Email. With the .flow file to import.

An order is paid, Workflow Documents renders the invoice from your template, and the customer gets it a moment later as a PDF attached to an email. This article builds that workflow in Shopify Flow, step by step, and offers the finished workflow as a file to import.

What you need

  • Workflow Documents with a template named Invoice that renders an order (the Invoice starter is exactly that).
  • Shopify Flow.
  • An app that adds a send email to anyone action to Flow and can attach a file from a link. Flow's own Send internal email only reaches your staff and cannot attach the PDF. This article uses our Workflow Transactional Email with a connected Microsoft 365, Google or SMTP sender.

The workflow

Step Setting Value
Trigger Order paid (Shopify) no configuration
Action Generate document (Workflow Documents) Order: order.id (filled in by Flow), Template name: Invoice, Language: empty
Action Send Transactional Email (Workflow Transactional Email) see below

The Generate document step returns the PDF: url (a download link that works for 7 days), filename, expiresAt, sizeBytes and documentId. In Flow's variable picker these appear under the step as generateDocument.

The Send Transactional Email step

Field Value
To Email(s) {{ order.email }}
Variables (JSON) see the code below
Config page (Configure Email) your sender and the layout Your invoice
Variables (JSON)json
{"order_name": "{{ order.name }}", "customer_name": "{{ order.customer.displayName }}", "invoice_url": "{{ generateDocument.url }}", "invoice_filename": "{{ generateDocument.filename }}"}

The email layout

In Workflow Transactional Email, create a transactional layout (text editor is enough), add one attachment from a link, and select the layout on the step's config page together with a sender. The attachment is what turns the download link into a PDF in the inbox: the app downloads the file when the email is sent and attaches it.

Setting Value
Name Your invoice
Subject Your invoice for order {{ variables.order_name }}
Preview text Your invoice is attached as a PDF.
Attachment: file name {{ variables.invoice_filename | default: "Invoice.pdf" }}
Attachment: link {{ variables.invoice_url }}
Bodyxml
<p>Hi {{ variables.customer_name | default: "there" }},</p>
<p>thank you for your order <strong>{{ variables.order_name }}</strong>. Your invoice is attached to this email as a PDF.</p>
<p>You can also <a href="{{ variables.invoice_url }}">download it here</a> (the link works for 7 days).</p>
<p>Kind regards<br>{{ shop.name }}</p>

Import the workflow instead

The file below is this workflow exported from Shopify Flow.

  1. In Shopify Flow, click Import and choose the .flow file.
  2. Open the Send Transactional Email step, click Configure Email and pick your sender and the layout with the attachment. The file carries the fields of the step, not your sender and layout, so this is always needed once.
  3. Check that your template is named Invoice, or change Template name in the Generate document step.
  4. Turn on the workflow.

Test it

Mark an order as paid, or create a test order and collect its payment. The run appears in Shopify Flow under Recent runs, the PDF under Documents in Workflow Documents, and the email in Workflow Transactional Email's History. Flow's Test your workflow mode does not run the Generate document step (it cannot simulate an app action that returns data), so test with a real order.

Good to know

  • The language of the invoice: with Language empty, the template is rendered in the customer's language when the template has it, otherwise in its main language. See Templates in several languages.
  • Only paid orders: Order paid fires once, when the payment is captured. For invoices at order time use Order created instead.
  • Each generated document counts toward your plan: one invoice per paid order. See Plans and pricing.
  • Larger PDFs: email providers cap attachments at about 20 MB. An invoice is far below that; a template with many large images may not be.

Next steps