首頁/部落格/n8n 實戰教學:電商訂單自動通知系統完整指南
n8n 教學

n8n 實戰教學:電商訂單自動通知系統完整指南

使用 n8n 建立電商訂單自動通知系統,支援 Shopify、WooCommerce、蝦皮等平台。自動發送訂單確認、出貨通知、評價邀請,多管道觸及(Email、LINE、簡訊)。

AutoAgent2026/1/230 分鐘閱讀9 次瀏覽
n8n 實戰教學:電商訂單自動通知系統完整指南

n8n 實戰教學:電商訂單自動通知系統完整指南

[Image blocked: 電商訂單通知自動化]

前言:為什麼電商需要自動化訂單通知?

經營電商最怕什麼?漏單、延遲出貨、客戶抱怨。這些問題的根源往往是「資訊傳遞不即時」——訂單進來了,但負責人沒有第一時間收到通知;貨物出貨了,但客戶不知道物流進度。

傳統做法是安排專人盯著後台,但這不僅浪費人力,還容易出錯。更聰明的做法是建立一套自動化訂單通知系統,讓系統自動:

  • 新訂單進來 → 立即通知倉管和客服
  • 訂單出貨 → 自動發送物流通知給客戶
  • 訂單完成 → 邀請客戶評價
  • 異常狀況 → 即時警報給負責人

本篇教學將帶你使用 n8n 建立一套完整的電商訂單自動通知系統,支援多種通知管道(Email、LINE、簡訊),並整合常見的電商平台(Shopify、WooCommerce、蝦皮)。


🎬 影片教學

如果你更喜歡透過影片學習,可以觀看以下教學影片:

💡 提示:影片中會有更詳細的操作示範,建議搭配文字教學一起學習效果更佳。

系統架構總覽

電商平台訂單 ──→ Webhook 觸發 ──→ n8n 接收


                              解析訂單資料

                    ┌───────────────┼───────────────┐
                    ↓               ↓               ↓
               新訂單通知      出貨通知        完成通知
                    │               │               │
                    ↓               ↓               ↓
            ┌───────┴───────┐   發送給客戶    邀請評價
            ↓               ↓
        通知倉管        通知客服
            │               │
            ↓               ↓
    ┌───────┴───────────────┴───────┐
    ↓           ↓           ↓       ↓
  Email       LINE      簡訊    Slack


                            記錄到資料庫

通知管道比較

管道優點缺點適用場景
Email免費、可附檔案、正式開信率低、可能進垃圾郵件訂單確認、發票
LINE開信率高、即時需要客戶加好友出貨通知、促銷
簡訊觸及率最高有成本、字數限制重要通知、驗證碼
Slack團隊協作方便僅限內部內部訂單通知

第一階段:電商平台 Webhook 設定

Shopify 設定

  1. 登入 Shopify 後台
  2. 前往「設定」→「通知」→「Webhook」
  3. 點選「建立 Webhook」
  4. 選擇事件類型:
    • orders/create(新訂單)
    • orders/fulfilled(訂單出貨)
    • orders/cancelled(訂單取消)
  5. 貼上 n8n Webhook URL
  6. 選擇格式為 JSON

Shopify 訂單資料格式:

json
{
  "id": 820982911946154508,
  "email": "[email protected]",
  "created_at": "2024-01-15T10:30:00+08:00",
  "total_price": "1299.00",
  "currency": "TWD",
  "financial_status": "paid",
  "fulfillment_status": null,
  "customer": {
    "first_name": "王",
    "last_name": "小明",
    "phone": "+886912345678"
  },
  "shipping_address": {
    "address1": "台北市中山區南京東路三段123號",
    "city": "台北市",
    "zip": "104"
  },
  "line_items": [
    {
      "title": "經典款 T-shirt",
      "quantity": 2,
      "price": "599.00"
    }
  ]
}

WooCommerce 設定

  1. 安裝 WooCommerce Webhooks 外掛
  2. 前往「WooCommerce」→「設定」→「進階」→「Webhooks」
  3. 新增 Webhook:
    • 名稱:n8n 訂單通知
    • 狀態:啟用
    • 主題:訂單已建立
    • 傳送 URL:n8n Webhook URL
    • 密鑰:自訂密鑰(用於驗證)

蝦皮設定

蝦皮需要透過 Open API 來取得訂單資訊:

  1. 申請蝦皮開放平台帳號
  2. 建立應用程式取得 Partner ID 和 Key
  3. 使用 n8n 的排程觸發,定期呼叫蝦皮 API 檢查新訂單
javascript
// 蝦皮 API 簽名生成
const crypto = require('crypto');

const partnerId = 'your_partner_id';
const partnerKey = 'your_partner_key';
const timestamp = Math.floor(Date.now() / 1000);
const path = '/api/v2/order/get_order_list';

const baseString = `${partnerId}${path}${timestamp}`;
const sign = crypto.createHmac('sha256', partnerKey)
  .update(baseString)
  .digest('hex');

第二階段:n8n 工作流程建立

步驟 1:建立 Webhook 接收節點

json
{
  "nodes": [
    {
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "parameters": {
        "httpMethod": "POST",
        "path": "ecommerce-order",
        "responseMode": "onReceived"
      }
    }
  ]
}

步驟 2:解析訂單資料

新增「Code」節點統一處理不同平台的訂單格式:

javascript
// 統一訂單資料格式
const input = $input.first().json;
let order = {};

// 判斷來源平台
if (input.id && input.line_items) {
  // Shopify 格式
  order = {
    platform: 'shopify',
    orderId: input.id.toString(),
    orderNumber: input.order_number || input.name,
    customerName: `${input.customer?.last_name || ''}${input.customer?.first_name || ''}`.trim() || '顧客',
    customerEmail: input.email,
    customerPhone: input.customer?.phone || input.shipping_address?.phone,
    totalAmount: parseFloat(input.total_price),
    currency: input.currency || 'TWD',
    status: input.fulfillment_status || 'unfulfilled',
    paymentStatus: input.financial_status,
    shippingAddress: [
      input.shipping_address?.address1,
      input.shipping_address?.city,
      input.shipping_address?.zip
    ].filter(Boolean).join(' '),
    items: input.line_items.map(item => ({
      name: item.title,
      quantity: item.quantity,
      price: parseFloat(item.price)
    })),
    createdAt: input.created_at
  };
} else if (input.order_id && input.order_sn) {
  // 蝦皮格式
  order = {
    platform: 'shopee',
    orderId: input.order_sn,
    orderNumber: input.order_sn,
    customerName: input.recipient_address?.name || '顧客',
    customerPhone: input.recipient_address?.phone,
    totalAmount: input.total_amount / 100000, // 蝦皮金額單位轉換
    currency: 'TWD',
    status: input.order_status,
    shippingAddress: input.recipient_address?.full_address,
    items: input.item_list?.map(item => ({
      name: item.item_name,
      quantity: item.model_quantity_purchased,
      price: item.model_discounted_price / 100000
    })) || [],
    createdAt: new Date(input.create_time * 1000).toISOString()
  };
} else if (input.id && input.billing) {
  // WooCommerce 格式
  order = {
    platform: 'woocommerce',
    orderId: input.id.toString(),
    orderNumber: input.number,
    customerName: `${input.billing.last_name}${input.billing.first_name}`,
    customerEmail: input.billing.email,
    customerPhone: input.billing.phone,
    totalAmount: parseFloat(input.total),
    currency: input.currency,
    status: input.status,
    shippingAddress: [
      input.shipping.address_1,
      input.shipping.city,
      input.shipping.postcode
    ].filter(Boolean).join(' '),
    items: input.line_items.map(item => ({
      name: item.name,
      quantity: item.quantity,
      price: parseFloat(item.price)
    })),
    createdAt: input.date_created
  };
}

// 計算商品清單文字
order.itemsText = order.items
  .map(item => `• ${item.name} x ${item.quantity} - NT$ ${item.price * item.quantity}`)
  .join('\n');

return [{ json: order }];

步驟 3:判斷訂單狀態並路由

使用「Switch」節點根據訂單狀態分流:

json
{
  "rules": [
    {
      "conditions": {
        "status": ["unfulfilled", "pending", "processing"]
      },
      "output": "新訂單"
    },
    {
      "conditions": {
        "status": ["fulfilled", "shipped", "completed"]
      },
      "output": "已出貨"
    },
    {
      "conditions": {
        "status": ["cancelled", "refunded"]
      },
      "output": "已取消"
    }
  ]
}

步驟 4:新訂單通知設定

通知倉管(Slack)

json
{
  "channel": "#orders",
  "text": "🛒 新訂單通知",
  "attachments": [
    {
      "color": "#36a64f",
      "fields": [
        {
          "title": "訂單編號",
          "value": "{{ $json.orderNumber }}",
          "short": true
        },
        {
          "title": "金額",
          "value": "NT$ {{ $json.totalAmount }}",
          "short": true
        },
        {
          "title": "客戶",
          "value": "{{ $json.customerName }}",
          "short": true
        },
        {
          "title": "電話",
          "value": "{{ $json.customerPhone }}",
          "short": true
        },
        {
          "title": "商品",
          "value": "{{ $json.itemsText }}"
        },
        {
          "title": "寄送地址",
          "value": "{{ $json.shippingAddress }}"
        }
      ]
    }
  ]
}

通知客服(LINE Notify)

javascript
const message = `
🛒 新訂單通知

📦 訂單編號:${$json.orderNumber}
👤 客戶:${$json.customerName}
📱 電話:${$json.customerPhone}
💰 金額:NT$ ${$json.totalAmount}

📝 商品明細:
${$json.itemsText}

📍 寄送地址:
${$json.shippingAddress}

⏰ 下單時間:${new Date($json.createdAt).toLocaleString('zh-TW')}
`;

return [{ json: { message } }];

發送訂單確認信給客戶(Email)

html
<!DOCTYPE html>
<html>
<head>
  <style>
    body { font-family: 'Microsoft JhengHei', sans-serif; }
    .container { max-width: 600px; margin: 0 auto; padding: 20px; }
    .header { background: #4A90D9; color: white; padding: 20px; text-align: center; }
    .content { padding: 20px; background: #f9f9f9; }
    .order-info { background: white; padding: 15px; margin: 10px 0; border-radius: 8px; }
    .item { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid #eee; }
    .total { font-size: 1.2em; font-weight: bold; text-align: right; margin-top: 15px; }
    .footer { text-align: center; padding: 20px; color: #666; font-size: 12px; }
  </style>
</head>
<body>
  <div class="container">
    <div class="header">
      <h1>訂單確認</h1>
      <p>感謝您的訂購!</p>
    </div>
    <div class="content">
      <div class="order-info">
        <h3>訂單資訊</h3>
        <p><strong>訂單編號:</strong>{{ $json.orderNumber }}</p>
        <p><strong>訂購日期:</strong>{{ $json.createdAt }}</p>
      </div>
      
      <div class="order-info">
        <h3>商品明細</h3>
        {{#each items}}
        <div class="item">
          <span>{{ this.name }} x {{ this.quantity }}</span>
          <span>NT$ {{ this.price }}</span>
        </div>
        {{/each}}
        <div class="total">
          總計:NT$ {{ $json.totalAmount }}
        </div>
      </div>
      
      <div class="order-info">
        <h3>寄送資訊</h3>
        <p><strong>收件人:</strong>{{ $json.customerName }}</p>
        <p><strong>電話:</strong>{{ $json.customerPhone }}</p>
        <p><strong>地址:</strong>{{ $json.shippingAddress }}</p>
      </div>
    </div>
    <div class="footer">
      <p>如有任何問題,請聯繫客服:[email protected]</p>
      <p>© 2024 Your Store. All rights reserved.</p>
    </div>
  </div>
</body>
</html>

步驟 5:出貨通知設定

當訂單狀態變更為「已出貨」時,自動發送物流通知給客戶:

LINE 推播通知

json
{
  "to": "{{ $json.lineUserId }}",
  "messages": [
    {
      "type": "flex",
      "altText": "您的訂單已出貨",
      "contents": {
        "type": "bubble",
        "header": {
          "type": "box",
          "layout": "vertical",
          "contents": [
            {
              "type": "text",
              "text": "📦 您的訂單已出貨!",
              "weight": "bold",
              "size": "lg",
              "color": "#ffffff"
            }
          ],
          "backgroundColor": "#27ACB2"
        },
        "body": {
          "type": "box",
          "layout": "vertical",
          "contents": [
            {
              "type": "text",
              "text": "訂單編號",
              "size": "sm",
              "color": "#aaaaaa"
            },
            {
              "type": "text",
              "text": "{{ $json.orderNumber }}",
              "weight": "bold",
              "size": "lg",
              "margin": "sm"
            },
            {
              "type": "separator",
              "margin": "lg"
            },
            {
              "type": "text",
              "text": "物流資訊",
              "size": "sm",
              "color": "#aaaaaa",
              "margin": "lg"
            },
            {
              "type": "text",
              "text": "{{ $json.shippingCarrier }}",
              "margin": "sm"
            },
            {
              "type": "text",
              "text": "追蹤編號:{{ $json.trackingNumber }}",
              "size": "sm",
              "color": "#666666",
              "margin": "sm"
            }
          ]
        },
        "footer": {
          "type": "box",
          "layout": "vertical",
          "contents": [
            {
              "type": "button",
              "action": {
                "type": "uri",
                "label": "查詢物流進度",
                "uri": "{{ $json.trackingUrl }}"
              },
              "style": "primary"
            }
          ]
        }
      }
    }
  ]
}

簡訊通知(適用於沒有 LINE 的客戶)

【商店名稱】您的訂單 {{ $json.orderNumber }} 已出貨!
物流:{{ $json.shippingCarrier }}
追蹤碼:{{ $json.trackingNumber }}
查詢:{{ $json.trackingUrl }}

步驟 6:訂單完成後邀請評價

訂單送達後 3 天,自動發送評價邀請:

javascript
// 使用 n8n 的 Wait 節點延遲 3 天
// 或使用排程任務檢查已完成訂單

const message = `
親愛的 ${$json.customerName} 您好:

感謝您購買我們的商品!🙏

您的訂單 ${$json.orderNumber} 已經送達,希望您對商品感到滿意。

如果方便的話,能否花 1 分鐘給我們一個評價呢?
您的回饋對我們非常重要!

👉 點此評價:${$json.reviewUrl}

再次感謝您的支持!
${$json.storeName} 團隊敬上
`;

步驟 7:記錄到資料庫

將所有訂單通知記錄到 Google Sheets 或資料庫:

json
{
  "operation": "append",
  "values": [
    "{{ $now.toISO() }}",
    "{{ $json.platform }}",
    "{{ $json.orderNumber }}",
    "{{ $json.customerName }}",
    "{{ $json.totalAmount }}",
    "{{ $json.status }}",
    "{{ $json.notificationType }}",
    "{{ $json.notificationChannel }}",
    "success"
  ]
}

第三階段:進階功能

功能 1:庫存不足警報

當訂單中的商品庫存低於安全水位時,自動發送警報:

javascript
// 檢查庫存
const lowStockItems = [];

for (const item of $json.items) {
  const stock = await checkStock(item.sku);
  if (stock < 10) {
    lowStockItems.push({
      name: item.name,
      sku: item.sku,
      currentStock: stock
    });
  }
}

if (lowStockItems.length > 0) {
  return [{
    json: {
      alert: true,
      message: `⚠️ 庫存警報:以下商品庫存不足\n${lowStockItems.map(i => `• ${i.name} (${i.sku}): 剩餘 ${i.currentStock} 件`).join('\n')}`
    }
  }];
}

功能 2:VIP 客戶特殊處理

針對 VIP 客戶提供優先處理和專屬通知:

javascript
// 判斷是否為 VIP 客戶
const vipCustomers = ['[email protected]', '[email protected]'];
const isVIP = vipCustomers.includes($json.customerEmail);

if (isVIP) {
  // VIP 專屬處理
  return [{
    json: {
      ...$json,
      isVIP: true,
      priority: 'high',
      notificationTemplate: 'vip'
    }
  }];
}

功能 3:異常訂單偵測

自動偵測可疑訂單並發送警報:

javascript
// 異常訂單偵測規則
const alerts = [];

// 規則 1:金額異常高
if ($json.totalAmount > 50000) {
  alerts.push('高金額訂單');
}

// 規則 2:同一客戶短時間內多筆訂單
const recentOrders = await getRecentOrdersByEmail($json.customerEmail, 24);
if (recentOrders.length > 5) {
  alerts.push('短時間內多筆訂單');
}

// 規則 3:寄送地址與帳單地址不同
if ($json.shippingAddress !== $json.billingAddress) {
  alerts.push('寄送地址與帳單地址不同');
}

if (alerts.length > 0) {
  return [{
    json: {
      ...$json,
      isAbnormal: true,
      alerts: alerts
    }
  }];
}

常見問題 FAQ

Q1:如何處理重複的 Webhook 請求?

電商平台有時會重複發送 Webhook,建議使用訂單 ID 做去重:

javascript
const processedOrders = new Set();

if (processedOrders.has($json.orderId)) {
  return []; // 跳過重複訂單
}

processedOrders.add($json.orderId);

Q2:通知發送失敗怎麼辦?

建議設定重試機制和備用通知管道:

javascript
// 主要管道:LINE
try {
  await sendLineNotification($json);
} catch (error) {
  // 備用管道:Email
  await sendEmailNotification($json);
  // 記錄錯誤
  await logError('LINE notification failed', error);
}

Q3:如何測試 Webhook?

  1. 使用 n8n 的測試功能發送模擬請求
  2. 使用 Postman 或 curl 發送測試資料
  3. 在電商平台建立測試訂單

總結

透過這篇教學,你已經學會如何使用 n8n 建立一套完整的電商訂單自動通知系統。這個系統可以:

  1. 即時通知:新訂單進來立即通知相關人員
  2. 多管道觸及:Email、LINE、簡訊、Slack 全方位覆蓋
  3. 客戶體驗提升:自動發送訂單確認、出貨通知、評價邀請
  4. 異常偵測:自動識別可疑訂單,降低風險

這套系統可以大幅減少人工作業,讓你專注在更重要的事情上。如果你在設定過程中遇到任何問題,歡迎到我們的 n8n 資源頁面 [blocked] 下載完整的工作流程模板。


相關資源:

立即試用相關工具

馬上體驗文章中提到的功能