Trình Kết Nối WooCommerce

Trình Kết Nối WooCommerce

Kết nối cửa hàng WooCommerce của bạn với Brevo qua Tajo để đồng bộ dữ liệu customers và orders, kích hoạt email abandoned cart và tự động hóa marketing dựa trên hành vi mua hàng.

Tổng Quan

Thuộc TínhGiá Trị
Nền TảngWooCommerce
Danh MụcThương Mại Điện Tử
Độ Phức Tạp Thiết LậpTrung Bình
Tích Hợp Chính Thức
Dữ Liệu Đồng BộCustomers, Orders, Products, Subscriptions
URL APIhttps://yourstore.com/wp-json/wc/v3

Tính Năng

  • Đồng bộ customers - Nhập WooCommerce customers sang liên hệ Brevo
  • Đồng bộ orders - Theo dõi trạng thái orders và kích hoạt email tương ứng
  • Catalog sản phẩm - Đồng bộ products cho email cá nhân hóa
  • Abandoned cart - Kích hoạt campaigns recovery khi cart bị bỏ
  • WooCommerce Subscriptions - Đồng bộ dữ liệu subscription cho renewal campaigns
  • Webhooks - Cập nhật theo thời gian thực qua WooCommerce webhooks

Yêu Cầu

Trước khi bắt đầu, hãy đảm bảo bạn có:

  1. WordPress website với WooCommerce được cài đặt
  2. WooCommerce REST API credentials (Consumer Key và Secret)
  3. SSL certificate (HTTPS) trên website
  4. Tài khoản Brevo với quyền truy cập API
  5. Tài khoản Tajo

Xác Thực

REST API Keys

WooCommerce sử dụng xác thực OAuth 1.0a hoặc Basic Auth qua HTTPS.

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

Tạo API keys trong WooCommerce Settings > Advanced > REST API.

Hiệu Năng Server

WooCommerce chạy trên WordPress, vốn không được thiết kế cho API calls khối lượng cao. Giới hạn tốc độ đồng bộ để tránh làm chậm website bán hàng của bạn.

Cấu Hình

Thiết Lập Cơ Bản

connectors:
woocommerce:
enabled: true
store_url: "https://yourstore.com"
consumer_key: "${WC_CONSUMER_KEY}"
consumer_secret: "${WC_CONSUMER_SECRET}"
sync:
customers: true
orders: true
products: false
subscriptions: true
brevo_list_ids:
all_customers: 25
buyers: 26
subscribers: 27

Ánh Xạ Trường

Ánh Xạ Mặc Định

Parameter Type Description
email required
string

Email khách hàng (định danh duy nhất)

first_name optional
string

Ánh xạ sang thuộc tính FIRSTNAME

last_name optional
string

Ánh xạ sang thuộc tính LASTNAME

billing.phone optional
string

Số điện thoại billing

orders_count optional
integer

Tổng số orders đã đặt

total_spent optional
string

Tổng chi tiêu của khách hàng

API Endpoints

Phương ThứcEndpointMô Tả
GET/wc/v3/customersLiệt kê customers
GET/wc/v3/ordersLiệt kê orders
GET/wc/v3/productsLiệt kê products
GET/wc/v3/couponsLiệt kê coupons
POST/wc/v3/webhooksTạo webhook
GET/wc/v3/reports/salesBáo cáo doanh thu

Sự Kiện

Sự KiệnKích HoạtTrường Hợp Sử Dụng
order.createdOrder mới được đặtEmail xác nhận
order.updatedTrạng thái order thay đổiCập nhật vận chuyển
customer.createdKhách hàng mới đăng kýEmail chào mừng
product.updatedSản phẩm cập nhậtThông báo có hàng
coupon.createdCoupon mới được tạoCampaign giảm giá

Ví Dụ Code

Khởi Tạo Trình Kết Nối

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

Đồng Bộ Customers và Orders

// Đồng bộ WooCommerce sang Brevo
await tajo.connectors.sync('woocommerce', {
type: 'incremental',
resources: ['customers', 'orders'],
since: '2024-01-01',
batchSize: 50 // Giảm batch size để bảo vệ server
});

Xác Minh Webhook WooCommerce

// Xác minh WooCommerce webhook signature
app.post('/webhooks/woocommerce', async (req, res) => {
const signature = req.get('X-WC-Webhook-Signature');
const payload = JSON.stringify(req.body);
const expectedSig = crypto
.createHmac('sha256', process.env.WC_WEBHOOK_SECRET)
.update(payload, 'utf8')
.digest('base64');
if (signature !== expectedSig) {
return res.status(401).send('Unauthorized');
}
await tajo.connectors.handleWebhook('woocommerce', req.body);
res.status(200).send('OK');
});

Giới Hạn Tốc Độ

WooCommerce không có giới hạn tốc độ API cụ thể, nhưng bị giới hạn bởi hiệu năng WordPress server:

Khuyến NghịGiá Trị
Yêu cầu đồng thời2-5
Kích thước batch50-100
Delay giữa requests100-500ms

Khắc Phục Sự Cố

Sự CốNguyên NhânGiải Pháp
401 UnauthorizedConsumer key/secret saiTạo lại API keys trong WooCommerce settings
404 Not FoundURL sai hoặc REST API tắtBật Permalink settings, kiểm tra REST API enabled
TimeoutServer quá tảiGiảm batch size và thêm delay
Webhooks không nhậnSSL hoặc URL saiĐảm bảo HTTPS và URL có thể truy cập

Tài Nguyên Liên Quan

Subscribe to updates

developer-docs

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

Trợ lý AI

Xin chào! Hãy hỏi tôi về tài liệu.

Bắt đầu miễn phí với Brevo