Send a PDF when an order is sent to Mechanic, with Mechanic.

Mechanic is a development and ecommerce automation platform for Shopify. :)

Send a PDF when an order is sent to Mechanic

Automatically generate a PDF to be emailed to the address on file for the order(s) when sent to Mechanic. This task listens for orders sent to Mechanic via Admin and Bulk action links in the Shopify admin.

Runs Occurs when a user sends orders to Mechanic and Occurs when a user sends an order to Mechanic. Configuration includes email subject, email body, pdf attachment filename, and pdf html template.

15-day free trial – unlimited tasks

Documentation

Automatically generate a PDF to be emailed to the address on file for the order(s) when sent to Mechanic. This task listens for orders sent to Mechanic via Admin and Bulk action links in the Shopify admin.

No email will be sent if the order does not have an email on file.

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Shopifolks, everybody.

That’s why we make it easy to configure automation without code, why we make it easy to tweak the underlying code once tasks are installed, and why we publish it all here for everyone to learn from.

(By the way, have you seen our documentation? Have you joined the Slack community?)

Open source
View on GitHub to contribute to this task
Subscriptions
mechanic/user/orders
mechanic/user/order
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
email subject (required), email body (multiline, required), pdf attachment filename (required), pdf html template (code, multiline, required)
Code
{% comment %}
  Preferred option order:

  {{ 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"
    }
  {% endcapture %}

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

{% if event.topic == "mechanic/user/order" or event.preview %}
  {% assign orders = array %}
  {% assign orders[0] = order %}
{% endif %}

{% comment %} 
  If this event topic is mechanic/user/orders the environment variable orders
  will already exist
{% endcomment %}

{% for order in orders %}
  {% if order.email != blank %}
    {% 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 %}
{% endfor %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more
Defaults
Email subject
Thanks for your order: {{ order.name }}
Email body
Hello,

Thank you for your order! Please see the attached receipt.

Thanks,
{{ shop.name }}
PDF attachment filename
receipt-{{ 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>