{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "WooCommerce New Order Notification via WhatsApp with MoltFlow",
  "tags": [
    {
      "name": "whatsapp"
    },
    {
      "name": "woocommerce"
    },
    {
      "name": "e-commerce"
    },
    {
      "name": "moltflow"
    },
    {
      "name": "wordpress"
    },
    {
      "name": "orders"
    }
  ],
  "nodes": [
    {
      "id": "m1000001-0000-4000-0d00-000000000010",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -40,
        -300
      ],
      "parameters": {
        "color": 4,
        "width": 400,
        "height": 300,
        "content": "## WooCommerce \u2192 WhatsApp Order Alert\nGet instant WhatsApp notifications when a new order is placed on your WooCommerce store, powered by [MoltFlow](https://molt.waiflow.app).\n\n**How it works:**\n1. WooCommerce fires a webhook on new order\n2. Order details are extracted (customer, items, total)\n3. A WhatsApp notification is sent to the store owner\n4. Optionally sends a confirmation to the customer too"
      },
      "typeVersion": 1
    },
    {
      "id": "m1000001-0000-4000-0d00-000000000011",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        -300
      ],
      "parameters": {
        "color": 5,
        "width": 400,
        "height": 240,
        "content": "## Setup (5 min)\n1. Create a [MoltFlow account](https://molt.waiflow.app) and connect WhatsApp\n2. Activate this workflow \u2014 copy the webhook URL\n3. In WooCommerce \u2192 Settings \u2192 Advanced \u2192 Webhooks, add a webhook for **Order created** pointing to this URL\n4. Set `YOUR_SESSION_ID` and `OWNER_PHONE` in the Format Order node\n5. Add MoltFlow API Key: Header Auth \u2192 `X-API-Key`"
      },
      "typeVersion": 1
    },
    {
      "id": "m1000001-0000-4000-0d00-000000000001",
      "name": "WooCommerce Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        0,
        0
      ],
      "parameters": {
        "path": "woo-order",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2
    },
    {
      "id": "m1000001-0000-4000-0d00-000000000002",
      "name": "Format Order",
      "type": "n8n-nodes-base.code",
      "position": [
        220,
        0
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const SESSION_ID = 'YOUR_SESSION_ID';\nconst OWNER_PHONE = 'YOUR_PHONE';\n\nconst order = $input.first().json.body || $input.first().json;\n\nconst orderId = order.id || order.number || 'N/A';\nconst status = order.status || 'new';\nconst total = order.total || '0.00';\nconst currency = order.currency || 'USD';\n\nconst billing = order.billing || {};\nconst customerName = (billing.first_name || '') + ' ' + (billing.last_name || '');\nconst customerEmail = billing.email || '';\nconst customerPhone = (billing.phone || '').replace(/[^0-9]/g, '');\n\nconst items = (order.line_items || []).map(item =>\n  item.name + ' x' + item.quantity\n).join(', ');\n\nconst ownerMsg = `New Order #${orderId}!\\n\\nCustomer: ${customerName.trim()}\\nItems: ${items}\\nTotal: ${currency} ${total}\\nStatus: ${status}\\n\\nCheck your WooCommerce dashboard for details.`;\n\nconst results = [{\n  json: {\n    session_id: SESSION_ID,\n    chat_id: OWNER_PHONE + '@c.us',\n    message: ownerMsg,\n    type: 'owner_notification',\n    order_id: orderId\n  }\n}];\n\nif (customerPhone && customerPhone.length >= 7) {\n  const customerMsg = `Hi ${customerName.trim() || 'there'}! Your order #${orderId} has been received. Total: ${currency} ${total}. We'll update you when it ships. Thank you!`;\n  results.push({\n    json: {\n      session_id: SESSION_ID,\n      chat_id: customerPhone + '@c.us',\n      message: customerMsg,\n      type: 'customer_confirmation',\n      order_id: orderId\n    }\n  });\n}\n\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "m1000001-0000-4000-0d00-000000000003",
      "name": "Send WhatsApp",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        440,
        0
      ],
      "parameters": {
        "url": "https://apiv2.waiflow.app/api/v2/messages/send",
        "method": "POST",
        "options": {},
        "jsonBody": "={{ JSON.stringify({ session_id: $json.session_id, chat_id: $json.chat_id, message: $json.message }) }}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "m1000001-0000-4000-0d00-000000000004",
      "name": "Log",
      "type": "n8n-nodes-base.code",
      "position": [
        660,
        0
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const items = $input.all();\nconst orderId = $('Format Order').first().json.order_id;\nreturn [{ json: { status: 'notified', order_id: orderId, messages_sent: items.length } }];"
      },
      "typeVersion": 2
    }
  ],
  "settings": {
    "executionOrder": "v1"
  },
  "connections": {
    "Format Order": {
      "main": [
        [
          {
            "node": "Send WhatsApp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send WhatsApp": {
      "main": [
        [
          {
            "node": "Log",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WooCommerce Webhook": {
      "main": [
        [
          {
            "node": "Format Order",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}