WooCommerce Connector

WooCommerce Connector

เชื่อมต่อร้านค้า WooCommerce ของคุณกับ Brevo ผ่าน Tajo เพื่อการซิงค์ข้อมูล e-commerce ที่สมบูรณ์ ใช้ WooCommerce REST API เพื่อซิงค์ลูกค้า คำสั่งซื้อ สินค้า และข้อมูลคูปองสำหรับแคมเปญการตลาดที่กำหนดเป้าหมายและเวิร์กโฟลว์อัตโนมัติ

ภาพรวม

คุณสมบัติค่า
แพลตฟอร์มWooCommerce (WordPress)
หมวดหมู่E-commerce
ความซับซ้อนในการตั้งค่าปานกลาง
การผสานรวมอย่างเป็นทางการไม่
ข้อมูลที่ซิงค์ลูกค้า คำสั่งซื้อ สินค้า คูปอง
ทักษะที่ใช้ได้10

ฟีเจอร์

  • การซิงค์ลูกค้า - การซิงค์ข้อมูลลูกค้าแบบเรียลไทม์กับผู้ติดต่อ Brevo
  • การติดตามคำสั่งซื้อ - การติดตามเหตุการณ์ order lifecycle ที่สมบูรณ์สำหรับเวิร์กโฟลว์หลังการซื้อ
  • การซิงค์แคตาล็อกสินค้า - ซิงค์สินค้าและ variations สำหรับคำแนะนำในอีเมล
  • การจัดการคูปอง - ซิงค์รหัสคูปองสำหรับแคมเปญโปรโมชัน
  • รองรับ webhook - การอัปเดตแบบเรียลไทม์ผ่าน WooCommerce webhooks
  • การละทิ้ง cart - ติดตามและกู้คืน carts ที่ถูกละทิ้ง
  • รองรับหลาย site - เชื่อมต่อการติดตั้ง WordPress multisite WooCommerce
  • Custom meta fields - แมป WooCommerce custom meta กับแอตทริบิวต์ Brevo

ข้อกำหนดเบื้องต้น

ก่อนเริ่มต้น ตรวจสอบให้แน่ใจว่าคุณมี:

  1. WordPress site ที่ติดตั้งและเปิดใช้งาน WooCommerce plugin
  2. WooCommerce REST API ที่เปิดใช้งาน (Settings > Advanced > REST API)
  3. API Consumer Key และ Consumer Secret ที่สร้างแล้ว
  4. Site ของคุณต้องใช้ HTTPS สำหรับการยืนยันตัวตน API
  5. บัญชี Brevo ที่มีสิทธิ์เข้าถึง API
  6. บัญชี Tajo ที่มีข้อมูลประจำตัว API

การยืนยันตัวตน

REST API Keys

WooCommerce ใช้คู่ Consumer Key และ Consumer Secret สำหรับการยืนยันตัวตน สร้างได้ที่ WooCommerce > Settings > Advanced > REST API

OAuth 1.0a (HTTPS sites)

Terminal window
curl https://yourstore.com/wp-json/wc/v3/orders \
-u "consumer_key:consumer_secret"

Query String Authentication (HTTPS)

Terminal window
curl "https://yourstore.com/wp-json/wc/v3/orders?consumer_key=ck_xxx&consumer_secret=cs_xxx"

ระดับสิทธิ์

สิทธิ์การเข้าถึง
Readดูทรัพยากรเท่านั้น
Writeสร้างและแก้ไขทรัพยากร
Read/Writeสิทธิ์ CRUD เต็มรูปแบบ

การกำหนดค่า

การตั้งค่าพื้นฐาน

connectors:
woocommerce:
enabled: true
store_url: "https://yourstore.com"
consumer_key: "ck_your_consumer_key"
consumer_secret: "cs_your_consumer_secret"
api_version: "wc/v3"
verify_ssl: true
# Data sync options
sync:
customers: true
orders: true
products: true
coupons: true
# Brevo list assignment
lists:
all_customers: 50
buyers: 51
abandoned_cart: 52

การแมปฟิลด์ลูกค้า

แมปฟิลด์ลูกค้า WooCommerce กับแอตทริบิวต์ Brevo:

customer_mapping:
email: email
first_name: FIRSTNAME
last_name: LASTNAME
billing.phone: SMS
billing.company: COMPANY
billing.city: CITY
billing.state: STATE
billing.country: COUNTRY
billing.postcode: ZIP
# E-commerce metrics (computed)
orders_count: ORDER_COUNT
total_spent: TOTAL_SPENT
date_created: SIGNUP_DATE
# Meta fields
meta_data.loyalty_points: LOYALTY_POINTS
meta_data.preferred_category: PREF_CATEGORY

การกำหนดค่า Webhook

ลงทะเบียน webhooks ใน WooCommerce > Settings > Advanced > Webhooks:

webhooks:
- topic: "customer.created"
event: "customer_created"
- topic: "customer.updated"
event: "customer_updated"
- topic: "order.created"
event: "order_placed"
- topic: "order.updated"
event: "order_updated"
- topic: "order.completed"
event: "order_fulfilled"
- topic: "order.refunded"
event: "order_refunded"
- topic: "coupon.created"
event: "coupon_created"
- topic: "product.created"
event: "product_added"
- topic: "product.updated"
event: "product_updated"

API Endpoints

เมธอดEndpointคำอธิบาย
GET/wc/v3/customersแสดงรายการลูกค้า
POST/wc/v3/customersสร้างลูกค้า
GET/wc/v3/customers/{id}ดูลูกค้า
PUT/wc/v3/customers/{id}อัปเดตลูกค้า
GET/wc/v3/ordersแสดงรายการคำสั่งซื้อ
POST/wc/v3/ordersสร้างคำสั่งซื้อ
GET/wc/v3/orders/{id}ดูคำสั่งซื้อ
GET/wc/v3/productsแสดงรายการสินค้า
GET/wc/v3/products/{id}ดูสินค้า
GET/wc/v3/products/{id}/variationsแสดงรายการ product variations
GET/wc/v3/couponsแสดงรายการคูปอง
GET/wc/v3/reports/salesดูรายงานยอดขาย
GET/wc/v3/reports/top_sellersดูสินค้าขายดี
POST/wc/v3/webhooksสร้าง webhook

ตัวอย่างโค้ด

เริ่มต้น WooCommerce Connector

import { TajoClient } from '@tajo/sdk';
const tajo = new TajoClient({
apiKey: process.env.TAJO_API_KEY,
brevoApiKey: process.env.BREVO_API_KEY
});
// Connect WooCommerce store
await tajo.connectors.connect('woocommerce', {
storeUrl: 'https://yourstore.com',
consumerKey: process.env.WC_CONSUMER_KEY,
consumerSecret: process.env.WC_CONSUMER_SECRET
});

ดึงและซิงค์ลูกค้า

// Fetch customers using WooCommerce REST API
const WooCommerce = require('@woocommerce/woocommerce-rest-api').default;
const api = new WooCommerce({
url: 'https://yourstore.com',
consumerKey: process.env.WC_CONSUMER_KEY,
consumerSecret: process.env.WC_CONSUMER_SECRET,
version: 'wc/v3'
});
// List customers with pagination
const response = await api.get('customers', {
per_page: 100,
page: 1,
orderby: 'registered_date',
order: 'desc'
});
const customers = response.data;
// [{ id, email, first_name, last_name, billing, shipping, ... }]
// Pagination info from headers
const totalPages = response.headers['x-wp-totalpages'];
const totalItems = response.headers['x-wp-total'];

จัดการเหตุการณ์ Webhook

// WooCommerce webhook handler
app.post('/webhooks/woocommerce', async (req, res) => {
const topic = req.headers['x-wc-webhook-topic'];
const signature = req.headers['x-wc-webhook-signature'];
// Verify webhook signature
const expectedSignature = crypto
.createHmac('sha256', WEBHOOK_SECRET)
.update(JSON.stringify(req.body))
.digest('base64');
if (signature !== expectedSignature) {
return res.status(401).send('Invalid signature');
}
// Forward to Tajo
await tajo.connectors.handleWebhook('woocommerce', {
topic,
payload: req.body
});
res.status(200).send('OK');
});

การดำเนินการ Batch

// Batch create, update, and delete products
const batchResponse = await api.post('products/batch', {
create: [
{ name: 'New Product', type: 'simple', regular_price: '19.99' }
],
update: [
{ id: 123, regular_price: '24.99' }
],
delete: [456]
});

ขีดจำกัดอัตรา

WooCommerce เองไม่บังคับใช้ rate limits ของ API แต่เซิร์ฟเวอร์ WordPress และผู้ให้บริการ hosting อาจกำหนดขีดจำกัด:

ปัจจัยขีดจำกัดทั่วไปรายละเอียด
Shared hosting50-100 คำขอ/นาทีแตกต่างตาม host
Managed WP hosting200-500 คำขอ/นาทีWP Engine, Kinsta ฯลฯ
Self-hostedไม่มีขีดจำกัดที่แน่ชัดจำกัดโดยทรัพยากรเซิร์ฟเวอร์
ต่อหน้าสูงสุด 100 recordsค่าเริ่มต้นคือ 10
Batch operations100 รายการ/batchสร้าง อัปเดต หรือลบ

ประสิทธิภาพเซิร์ฟเวอร์

ร้านค้า WooCommerce ขนาดใหญ่อาจมีการตอบสนอง API ที่ช้า ใช้ pagination จำกัดฟิลด์ด้วยพารามิเตอร์ _fields และกำหนดเวลา bulk syncs ในช่วง off-peak

การแก้ไขปัญหา

ปัญหาสาเหตุวิธีแก้
401 UnauthorizedAPI keys ไม่ถูกต้องสร้าง Consumer Key/Secret ใหม่ในการตั้งค่า WooCommerce
403 Forbiddenสิทธิ์ไม่เพียงพอตั้งค่า API key เป็น Read/Write access
ข้อผิดพลาด SSL certificateSSL ไม่ถูกต้องบน siteตรวจสอบ SSL certificate ที่ถูกต้อง ตั้งค่า verify_ssl: false สำหรับการทดสอบเท่านั้น
Webhooks ไม่ทำงานWordPress cron ถูกปิดใช้งานเปิดใช้งาน WP-Cron หรือกำหนดค่า server-level cron
การตอบสนอง API ช้าฐานข้อมูลขนาดใหญ่ปรับแต่ง WordPress database ใช้พารามิเตอร์ _fields
Custom fields หายไปMeta data ไม่ถูกเปิดเผยใช้ฟิลด์ meta_data เพื่อเข้าถึง custom meta
ปัญหา paginationขนาดหน้าเริ่มต้นตั้งค่าพารามิเตอร์ per_page อย่างชัดเจน (สูงสุด 100)

แนวทางปฏิบัติที่ดีที่สุด

  1. ใช้ webhooks สำหรับ real-time sync - กำหนดค่า WooCommerce webhooks แทนการ polling API
  2. ตรวจสอบลายเซ็น webhook - ตรวจสอบ header X-WC-Webhook-Signature เสมอ
  3. แบ่งหน้าคำขอ list ทั้งหมด - ใช้พารามิเตอร์ page และ per_page ตรวจสอบ header X-WP-TotalPages
  4. ใช้พารามิเตอร์ _fields - ขอเฉพาะฟิลด์ที่จำเป็นเพื่อลดขนาดการตอบสนองและปรับปรุงประสิทธิภาพ
  5. Batch operations - ใช้ batch endpoints สำหรับการดำเนินการ bulk create/update/delete (สูงสุด 100 รายการ)
  6. กำหนดเวลา large syncs - รัน full syncs เริ่มต้นในช่วง off-peak เพื่อหลีกเลี่ยงความกดดันบนเซิร์ฟเวอร์
  7. เปิดใช้งาน HTTPS - WooCommerce API ต้องการการเข้ารหัส TLS สำหรับการยืนยันตัวตน OAuth

ความปลอดภัย

  • OAuth 1.0a - การยืนยันตัวตนที่ปลอดภัยผ่านคู่ Consumer Key/Secret
  • HMAC webhook signatures - การตรวจสอบลายเซ็น SHA-256 สำหรับ incoming webhooks
  • HTTPS จำเป็น - API ต้องการการเข้ารหัส TLS สำหรับการยืนยันตัวตน
  • Permission scoping - API keys สามารถตั้งค่าเป็น Read, Write หรือ Read/Write
  • ความปลอดภัย WordPress - ได้รับประโยชน์จากการอัปเดตความปลอดภัย WordPress core
  • ข้อพิจารณา PCI - ข้อมูลการชำระเงินจัดการโดย WooCommerce payment gateways ไม่เปิดเผยผ่าน API

แหล่งข้อมูลที่เกี่ยวข้อง

Subscribe to updates

developer-docs

Drop your email or phone number — we'll send you what matters next.

ผู้ช่วย AI

สวัสดี! ถามฉันเกี่ยวกับเอกสารได้เลย

เริ่มต้นฟรีกับ Brevo