Delete cancelled orders after 48 hours
When an order is cancelled, this task waits 48 hours, and then permanently deletes the order. Simple as that! (Please note: if you only want to archive the cancelled order, not delete it, try a different task!)
Try this taskWhen it runs
- Occurs whenever an order is updated
- Occurs whenever user/orders/delete_cancelled is triggered, with a 48 hour delay
Documentation
When an order is cancelled, this task waits 48 hours, and then permanently deletes the order. Simple as that! (Please note: if you only want to archive the cancelled order, not delete it, try a different task!)
When an order is cancelled, this task waits 48 hours, and then permanently deletes the order. There is no undo for deleting an order, so make sure this is what you want!
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/updated
user/orders/delete_cancelled+48.hours
How task subscriptions work
Task code
{% if event.topic == "shopify/orders/updated" %}
{% assign cache_key = "order-delete-scheduled-" | append: order.id %}
{% assign order_qualifies = false %}
{% if order.cancelled_at != blank and cache[cache_key] == blank %}
{% assign order_qualifies = true %}
{% endif %}
{% if event.preview or order_qualifies %}
{
"action": {
"type": "event",
"options": {
"topic": "user/orders/delete_cancelled",
"data": {
"order_id": {{ order.id | json }}
}
}
}
}
{
"action": {
"type": "cache",
"options": {
"setex": {
"key": {{ cache_key | json }},
"value": true,
"ttl": {{ 60 | times: 60 | times: 48 }}
}
}
}
}
{% endif %}
{% elsif event.topic == "user/orders/delete_cancelled" %}
{% assign order = shop.orders[event.data.order_id] %}
{% if order.cancelled_at != blank or event.preview %}
{
"action": {
"type": "shopify",
"options": [
"delete",
[
"order",
{{ event.data.order_id | json }}
]
]
}
}
{% endif %}
{% endif %}
Mechanic Liquid reference