Auto-tag new orders based on payment method with Mechanic.

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

Auto-tag new orders based on payment method

by Isaac Bowen (team@usemechanic.com)

This task checks the payment method for new orders immediately upon order creation, and tags the order accordingly. (If you need to tag the order later on, based on updates or when the order is paid, get in touch!)

Runs when an order is created. Configuration includes payment gateway name and comma separated tags to add.

15-day free trial – unlimited tasks

Developer details

Events
when an order is created (shopify/orders/create)
Options
payment gateway name (required), comma separated tags to add (required)
Script
{% assign order_qualifies = false %}
{% if order.payment_gateway_names contains options.payment_gateway_name__required %}
  {% assign order_qualifies = true %}
{% endif %}

{% if event.preview or order_qualifies %}
  {
    "action": {
      "type": "shopify",
      "options": [
        "update",
        [
          "order",
          {{ order.id }}
        ],
        {
          "tags": {{ options.comma_separated_tags_to_add__required | json }}
        }
      ]
    }
  }
{% endif %}

{% if event.preview != true and order_qualifies != true %}
  {% capture log_message %}
    The order did not qualify for auto-tagging. This task is configured to look for {{ options.payment_gateway_name__required | json }}; this order was paid using {{ order.payment_gateway_names | json }}.
  {% endcapture %}

  { "log": {{ log_message | strip | json }} }
{% endif %}
Yep, that’s just Liquid! If this is interesting to you, check out our documentation! Mechanic is hugely developer-friendly. :)