Auto-tag orders by shipment status with Mechanic.

Mechanic is the one-tool-does-it-all automation app for Shopify. :)

Auto-tag orders by shipment status

by Isaac Bowen (team@usemechanic.com)

Easily segment your orders by shipment status. Tagging your orders as "Delivered", or "Out for delivery", or "Attempted delivery", or any other status, allows you to stay on top of your order flow. And, adding these tags makes it easier to wire up additional automation, keeping the connection live between your customers and their orders.

Runs when a fulfillment is created and when a fulfillment is updated. Configuration includes shipping status tags.

15-day free trial – unlimited tasks

Documentation

This task monitors fulfillments for your orders. Whenever a fulfillment is updated, this task removes any shipment-related tags that might already be on the order, then adds whatever tag is relevant for the current shipment status. If there are multiple fulfillments for the order, and they have different statuses, this task will add more than one tag. (Naturally, if there are multiple fulfillments but they all have the same status, this task will only add one tag to the order.)

This task comes pre-configured with friendly tags, but feel free to update the tag names on the right-hand side. Do not modify the labels on the left! These correspond directly to shipment statuses as they're recorded by Shopify.

For a complete description of all Shopify shipment statuses, see Shopify's "shipment_status" documentation.

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Gurus, 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.

Events
when a fulfillment is created (shopify/fulfillments/create)
when a fulfillment is updated (shopify/fulfillments/update)
Options
shipping status tags (keyval, required)
Script
{% assign order = fulfillment.order %}
{% assign order_tags_to_save = order.tags %}

{% for keyval in options.shipping_status_tags__keyval_required %}
  {% assign order_tags_to_save = order_tags_to_save | remove_tag: keyval[1] %}
{% endfor %}

{% for fulfillment in order.fulfillments %}
  {% assign order_tags_to_save = order_tags_to_save | add_tag: options.shipping_status_tags__keyval_required[fulfillment.shipment_status] %}
{% endfor %}

{% if event.preview or order.tags != order_tags_to_save %}
  {
    "action": {
      "type": "shopify",
      "options": [
        "update",
        [
          "order",
          {{ order.id | json }}
        ],
        {
          "tags": {{ order_tags_to_save | json }}
        }
      ]
    }
  }
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
Shipping status tags
{"label_printed"=>"Shipping label printed", "label_purchased"=>"Shipping label purchased", "attempted_delivery"=>"Delivery attempted", "ready_for_pickup"=>"Delivery ready for pickup", "confirmed"=>"Delivery confirmed", "in_transit"=>"Delivery in transit", "out_for_delivery"=>"Out for delivery", "delivered"=>"Delivery complete", "failure"=>"Delivery failed"}