Archive orders when tagged with Mechanic.

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

Archive orders when tagged

by Isaac Bowen (team@usemechanic.com)

Add a tag, have the order automatically archived/closed. Simple. :)

Runs when an order is created, when an order is updated, and when a user triggers the task. Configuration includes required tag.

15-day free trial – unlimited tasks

Documentation

This task monitors for new and updated orders, watching for the tag of your choice to be added. When the tag is found, this task will make sure the order is archived/closed.

Run this task manually to scan your older orders, archiving any that match your tag.

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
when an order is created (shopify/orders/create)
when an order is updated (shopify/orders/updated)
when a user triggers the task (mechanic/user/trigger)
Options
required tag (required)
Script
{% assign orders = array %}
{% if event.preview or event.topic contains "shopify/orders/" %}
  {% assign orders[0] = order %}
{% elsif event.topic == "mechanic/user/trigger" %}
  {% assign orders = shop.orders.open %}
{% endif %}

{% for order in orders %}
  {% assign order_tags = order.tags | downcase | split: ", " %}
  {% assign tag_to_match = options.required_tag__required | downcase | strip %}

  {% assign order_qualifies = false %}
  {% if order.closed_at == blank and order_tags contains tag_to_match %}
    {% assign order_qualifies = true %}
  {% endif %}

  {% if event.preview or order_qualifies %}
    {% action "shopify" %}
      mutation {
        orderClose(
          input: {
            id: {{ order.admin_graphql_api_id | json }}
          }
        ) {
          order {
            closed
            closedAt
          }
          userErrors {
            field
            message
          }
        }
      }
    {% endaction %}
  {% endif %}
{% endfor %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
Required tag
archive-me