Shopify shipping confirmation email with a tracking button
Shopify sends the Shipping confirmation email when you fulfill items with the customer notification turned on. Its template has a fulfillment object with everything about that shipment.
The variables
{{ fulfillment.tracking_company }} UPS
{{ fulfillment.tracking_numbers | first }} 1Z999AA10123456784
{{ fulfillment.tracking_urls | first }} the carrier's tracking page
{{ fulfillment.tracking_url }} also available for a single number
{{ fulfillment.item_count }}
{{ fulfillment.estimated_delivery_at }} only with some carriers and carrier-calculated rates
{% for line in fulfillment.fulfillment_line_items %}
{{ line.line_item.title }} × {{ line.quantity }}
{% endfor %}
Note the loop: each fulfillment line wraps the order's line item, so titles and images are under line.line_item, while line.quantity is the quantity in this shipment (it can be less than ordered on a partial shipment).
A tracking button that never breaks
{% assign number = fulfillment.tracking_numbers | first | default: '' %}
{% assign url = fulfillment.tracking_urls | first | default: fulfillment.tracking_url %}
{% if url == blank %}{% assign url = order_status_url %}{% endif %}
{% if number != '' %}
<p>{{ fulfillment.tracking_company | default: 'Carrier' }} tracking number: <strong>{{ number }}</strong></p>
<a href="{{ url }}" style="background:#1f6f5c;color:#fff;padding:12px 26px;border-radius:6px">Track your package</a>
{% else %}
<a href="{{ order_status_url }}">View your order</a>
{% endif %}
Why the fallbacks: a manual fulfillment can have a number but no tracking link (unknown carrier), or no number at all. Falling back to the order status page means the button always goes somewhere useful.
Multiple tracking numbers
One fulfillment can carry several numbers. Loop over fulfillment.tracking_numbers and use fulfillment.tracking_urls[forloop.index0] for the matching link.
Testing
Fulfill a test order with a tracking number and the customer notification on; the email arrives within minutes. Send test email on the template uses sample data.
Open the free designer