Auto-tag orders created from drafts
This task monitors for newly-created orders, and auto-tags any that were originally based on a Shopify draft order, using the tag of your choice.
Try this taskWhen it runs
Occurs whenever an order is created
What you choose
Tag to add
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
How task subscriptions work
Option types and flags
- Tag to add (required)
Task code
{% assign order_qualifies = false %}
{% if order.source_name == "shopify_draft_order" %}
{% assign order_qualifies = true %}
{% elsif order.source_name == "1830279" %}
{% comment %}
1830279 is the ID of the "Shopify Web" app. If we're seeing it here, it means that
the order was created via the /admin area.
{% endcomment %}
{% capture query %}
query {
order(id: {{ order.admin_graphql_api_id | json }}) {
app {
name
}
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% if event.preview %}
{% capture result_json %}
{
"data": {
"order": {
"app": {
"name": "Draft Orders"
}
}
}
}
{% endcapture %}
{% assign result = result_json | parse_json %}
{% endif %}
{% if result.data.order.app.name == "Draft Orders" %}
{% assign order_qualifies = true %}
{% else %}
{% log message: "Order does not qualify",
order_source_name: order.source_name,
order_app_name: result.data.order.app.name %}
{% endif %}
{% else %}
{% log message: "Order does not qualify",
order_source_name: order.source_name %}
{% endif %}
{% if order_qualifies %}
{% action "shopify" %}
mutation {
tagsAdd(
id: {{ order.admin_graphql_api_id | json }}
tags: {{ options.tag_to_add__required | json }}
) {
userErrors {
field
message
}
}
}
{% endaction %}
{% endif %}
Mechanic Liquid reference
Default option values
- Tag to add
from-draft