{
  "schema_version": "1.0.0",
  "id": "woocommerce-paid-order-log-flag",
  "title": "Log paid WooCommerce orders and flag the odd ones",
  "category": "ecommerce",
  "difficulty": "intermediate",
  "featured": true,
  "description": "Log each paid WooCommerce order and write a private order note on the risky ones, so the hold shows up right where the packer works.",
  "tags": [
    "woocommerce",
    "orders",
    "fraud-check",
    "google-sheets"
  ],
  "apps": [
    "WooCommerce",
    "Code by Zapier",
    "Google Sheets",
    "Filter by Zapier"
  ],
  "plan": {
    "minimum": "Professional",
    "reasons": [
      "multi-step Zap: 4 steps after the trigger",
      "Filter by Zapier",
      "premium app: WooCommerce"
    ]
  },
  "tasks": {
    "typical": 2,
    "max": 3
  },
  "trigger": {
    "app": "WooCommerce",
    "event": "Order Paid",
    "kind": "instant",
    "title": "Order paid",
    "why": "Fires when WooCommerce records payment for an order. Cash-on-delivery and bank-transfer orders arrive later, when they are marked paid.",
    "config": {
      "Store": "YOUR_WOOCOMMERCE_STORE"
    },
    "outputs": [
      "id",
      "number",
      "billing_email",
      "billing_first_name",
      "total",
      "currency",
      "shipping_country",
      "billing_country",
      "line_items_count",
      "line_item_names",
      "coupon_codes",
      "payment_method_title",
      "date_paid"
    ],
    "sample": "sample-trigger.json"
  },
  "steps": [
    {
      "key": "flags",
      "kind": "code",
      "app": "Code by Zapier",
      "event": "Run JavaScript",
      "title": "Check the order for odd signals",
      "why": "Same rules as the Shopify template. WooCommerce's order payload has no lifetime order count, so `customer_order_count` is fixed at 2 to switch the first-order rule off instead of flagging every new customer.",
      "code": {
        "language": "javascript",
        "module": "order-flags",
        "file": "code/order-flags.js"
      },
      "input_data": {
        "total": "{{trigger.total}}",
        "currency": "{{trigger.currency}}",
        "shipping_country": "{{trigger.shipping_country}}",
        "billing_country": "{{trigger.billing_country}}",
        "item_count": "{{trigger.line_items_count}}",
        "customer_order_count": "2",
        "discount_codes": "{{trigger.coupon_codes}}",
        "email": "{{trigger.billing_email}}",
        "high_value_threshold": "600"
      },
      "outputs": [
        "flags",
        "flag_count",
        "is_odd",
        "summary"
      ]
    },
    {
      "key": "log",
      "kind": "action",
      "app": "Google Sheets",
      "event": "Create Spreadsheet Row",
      "title": "Log the order",
      "why": "Keeps a running record of every paid order and what the check found.",
      "fields": {
        "Drive": "My Google Drive",
        "Spreadsheet": "Store orders",
        "Worksheet": "WooCommerce paid",
        "Columns": {
          "paid_at": "{{trigger.date_paid}}",
          "order_number": "{{trigger.number}}",
          "email": "{{trigger.billing_email}}",
          "total": "{{trigger.total}}",
          "currency": "{{trigger.currency}}",
          "payment_method": "{{trigger.payment_method_title}}",
          "flags": "{{flags.flags}}"
        }
      },
      "outputs": [
        "id",
        "row_number"
      ]
    },
    {
      "key": "odd",
      "kind": "filter",
      "app": "Filter by Zapier",
      "event": "Only continue if...",
      "title": "Only orders with at least one flag",
      "why": "Clean orders stop here.",
      "conditions": [
        [
          {
            "field": "{{flags.is_odd}}",
            "operator": "(Boolean) Is true"
          }
        ]
      ],
      "usually": false
    },
    {
      "key": "note",
      "kind": "action",
      "app": "WooCommerce",
      "event": "Create Order Note",
      "title": "Write a private note on the order",
      "why": "The note sits on the order screen the packer already has open. Private notes are not emailed to the customer.",
      "fields": {
        "Order": "{{trigger.id}}",
        "Note": "HOLD before shipping. Automatic check: {{flags.summary}}. Logged in the Store orders sheet, row {{log.row_number}}.",
        "Customer Note?": "No"
      },
      "outputs": [
        "id"
      ]
    }
  ]
}
