Delete cancelled orders after 48 hours, with Mechanic.

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

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!)

Runs Occurs whenever an order is updated and Occurs whenever user/orders/delete_cancelled is triggered, with a 48 hour delay.

15-day free trial – unlimited tasks

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!

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
shopify/orders/updated
user/orders/delete_cancelled+48.hours
Tasks use subscriptions to sign up for specific kinds of events. Learn more
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 %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more