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

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 %}
Yep, that’s just Liquid! If this is interesting to you, check out our documentation! Mechanic is hugely developer-friendly. :)