Mechanic Get Mechanic
Task library

Send a PDF invoice when an order is created

Automatically generate an invoice PDF, to be emailed to the address on file for the order, if the order has not yet been paid. Useful for working with billing departments, or with anyone else who needs an order summary auto-emailed. :)

Try this task

When it runs

Occurs whenever an order is created

What you choose

  • Days to wait before emailing
  • Email subject
  • Email body
  • PDF attachment filename
  • PDF HTML template

Documentation

Automatically generate an invoice PDF, to be emailed to the address on file for the order, if the order has not yet been paid. Useful for working with billing departments, or with anyone else who needs an order summary auto-emailed. :)

This task automatically generates a PDF, based on the supplied HTML template. Configure to taste! To use a template from Order Printer, see this guide.

No email will be sent if the order does not have an email on file, or if the order's financial status is not "pending".

Task code and subscriptions

You can edit the Liquid code after installing this task. View on GitHub or ask a question in the Mechanic Slack community.

Subscriptions

shopify/orders/create{% if options.days_to_wait_before_emailing__number %}+{{ options.days_to_wait_before_emailing__number }}.days{% endif %}
How task subscriptions work

Option types and flags

Task code

{% comment %}
  Preferred option order:

  {{ options.days_to_wait_before_emailing__number }}
  {{ options.email_subject__required }}
  {{ options.email_body__multiline_required }}
  {{ options.pdf_attachment_filename__required }}
  {{ options.pdf_html_template__code_multiline_required }}
{% endcomment %}

{% if event.preview %}
  {% capture order_json %}
    {
      "email": "customer@example.com",
      "financial_status": "pending"
    }
  {% endcapture %}

  {% assign order = order_json | parse_json %}
{% endif %}

{% if order.email != blank and order.financial_status == "pending" %}
  {% action "email" %}
    {
      "to": {{ order.email | json }},
      "subject": {{ options.email_subject__required | strip | json }},
      "body": {{ options.email_body__multiline_required | strip | newline_to_br | json }},
      "reply_to": {{ shop.customer_email | json }},
      "from_display_name": {{ shop.name | json }},
      "attachments": {
        {{ options.pdf_attachment_filename__required | json }}: {
          "pdf": {
            "html": {{ options.pdf_html_template__code_multiline_required | json }}
          }
        }
      }
    }
  {% endaction %}
{% endif %}
Mechanic Liquid reference

Default option values

Email subject
Attached: Invoice for order {{ order.name }}
Email body
Hello,

Thank you for your order! Please see the attached invoice for details and payment options.

Thanks,
{{ shop.name }}
PDF attachment filename
invoice-{{ order.order_number }}.pdf
PDF HTML template
<h1>Order {{ order.name }} for {{ shop.name }}</h1>

<h2>Items</h2>

<ul>
  {% for line_item in order.line_items %}
    <li>
      {{ line_item.quantity }} x {{ line_item.title }}: {{ line_item.price | money_with_currency }}
    </li>
  {% endfor %}
</ul>

<h2>Totals</h2>

<ul>
  <li>Items: {{ order.total_line_items_price | money_with_currency }}</li>
  <li>Discounts: {{ order.total_discounts | money_with_currency }}</li>
  <li>Subtotal: {{ order.subtotal_price | money_with_currency }}</li>
  <li>Total (including taxes, shipping, tips): {{ order.total_price | money_with_currency }}</li>
</ul>

<p>To arrange payment, contact {{ shop.customer_email }}.</p>