Cancel and close unpaid orders after two days with Mechanic.

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

Cancel and close unpaid orders after two days

by Isaac Bowen (team@usemechanic.com)

Clear the clutter in your orders list, automatically! This task checks the order two days after it's created, and cancels and closes the order if its financial status is still marked "pending".

Runs 2 days after an order is created. Configuration includes restock inventory, send cancellation email to customer, and tag to add to the order.

15-day free trial – unlimited tasks

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
2 days after an order is created (shopify/orders/create+2.days)
Options
restock inventory (boolean), send cancellation email to customer (boolean), tag to add to the order
Script
{% unless event.preview %}
  {% assign order = order.reload %}
{% endunless %}

{% if event.preview or order.financial_status == "pending" %}
  {
    "action": {
      "type": "shopify",
      "options": [
        "post",
        "/admin/orders/{{ order.id }}/cancel.json",
        {
          "restock": {{ options.restock_inventory__boolean | json }},
          "email": {{ options.send_cancellation_email_to_customer__boolean | json }}
        }
      ]
    }
  }

  {
    "action": {
      "type": "shopify",
      "options": [
        "post",
        "/admin/orders/{{ order.id }}/close.json",
        {}
      ]
    }
  }

  {% if options.tag_to_add_to_the_order != blank %}
    {% capture tags_to_save %}{{ order.tags }}, {{ options.tag_to_add_to_the_order }}{% endcapture %}

    {
      "action": {
        "type": "shopify",
        "options": [
          "update",
          ["order", {{ order.id }}],
          {
            "tags": {{ tags_to_save | json }}
          }
        ]
      }
    }
  {% endif %}
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.