WordPress / WooCommerce Integration Guide
Connect your WooCommerce store to ECOSIRE to sync orders, products, customers, and inventory. Orders placed in WooCommerce become Sales Orders in ECOSIRE; stock levels managed in ECOSIRE push to WooCommerce automatically.
Introduction
WooCommerce exposes its own REST API and webhook system. ECOSIRE integrates with both directions:
- WooCommerce → ECOSIRE: Orders, customers (via WooCommerce webhooks)
- ECOSIRE → WooCommerce: Product stock updates, order status pushes (via WooCommerce REST API)
Prerequisites
- WordPress 6.4+ with WooCommerce 8.0+
- SSL certificate on your WordPress site (required for webhooks)
- ECOSIRE API key
- WooCommerce REST API credentials (Consumer Key + Secret)
- PHP 8.1+ or a Node.js proxy server
Step 1 — Generate WooCommerce API Credentials
- In WordPress Admin, go to WooCommerce → Settings → Advanced → REST API.
- Click Add Key:
- Description:
ECOSIRE Integration - User:
admin - Permissions:
Read/Write
- Description:
- Copy the Consumer Key (
ck_...) and Consumer Secret (cs_...). - Store them in environment variables:
WC_CONSUMER_KEY=ck_your_consumer_key
WC_CONSUMER_SECRET=cs_your_consumer_secret
WC_SITE_URL=https://yourstore.com
Step 2 — Register WooCommerce Webhooks
Register webhooks to push new orders and customer updates to ECOSIRE. Either use the WooCommerce Admin UI or the API:
# Register order created webhook
curl -X POST https://yourstore.com/wp-json/wc/v3/webhooks \
-u ck_key:cs_secret \
-H "Content-Type: application/json" \
-d '{
"name": "ECOSIRE Order Created",
"topic": "order.created",
"delivery_url": "https://api.ecosire.com/api/webhooks/woocommerce/orders"
}'
# Register customer created webhook
curl -X POST https://yourstore.com/wp-json/wc/v3/webhooks \
-u ck_key:cs_secret \
-H "Content-Type: application/json" \
-d '{
"name": "ECOSIRE Customer Created",
"topic": "customer.created",
"delivery_url": "https://api.ecosire.com/api/webhooks/woocommerce/customers"
}'
Step 3 — Push WooCommerce Orders to ECOSIRE
Create a WordPress plugin or webhook handler to push orders:
// wp-content/plugins/ecosire-sync/ecosire-sync.php
add_action('woocommerce_new_order', 'sync_order_to_ecosire', 10, 1);
function sync_order_to_ecosire($order_id) {
$order = wc_get_order($order_id);
$billing = $order->get_address('billing');
// Find or create ECOSIRE contact
$response = wp_remote_post('https://api.ecosire.com/api/contacts', [
'headers' => [
'Authorization' => 'Bearer ' . ECOSIRE_API_KEY,
'Content-Type' => 'application/json',
],
'body' => json_encode([
'name' => $billing['first_name'] . ' ' . $billing['last_name'],
'email' => $billing['email'],
'phone' => $billing['phone'],
'type' => 'person',
]),
]);
$contact = json_decode(wp_remote_retrieve_body($response), true);
$contact_id = $contact['id'] ?? null;
// Create ECOSIRE order
$items = [];
foreach ($order->get_items() as $item) {
$items[] = [
'productId' => get_post_meta($item->get_product_id(), '_ecosire_product_id', true),
'quantity' => $item->get_quantity(),
'unitPrice' => intval($item->get_total() * 100),
];
}
wp_remote_post('https://api.ecosire.com/api/orders', [
'headers' => [
'Authorization' => 'Bearer ' . ECOSIRE_API_KEY,
'Content-Type' => 'application/json',
],
'body' => json_encode([
'contactId' => $contact_id,
'lineItems' => $items,
'currency' => strtolower(get_woocommerce_currency()),
]),
]);
}
Step 4 — Sync ECOSIRE Stock to WooCommerce
Run a Node.js sync script on a schedule (cron every 15 minutes):
import fetch from 'node-fetch';
import WooCommerceRestApi from '@woocommerce/woocommerce-rest-api';
const wc = new WooCommerceRestApi({
url: process.env.WC_SITE_URL!,
consumerKey: process.env.WC_CONSUMER_KEY!,
consumerSecret: process.env.WC_CONSUMER_SECRET!,
version: 'wc/v3',
});
async function syncStockToWooCommerce() {
// Fetch ECOSIRE inventory
const res = await fetch('https://api.ecosire.com/api/inventory/products?limit=100', {
headers: { Authorization: `Bearer ${process.env.ECOSIRE_API_KEY}` },
});
const { data: products } = await res.json();
for (const product of products) {
const wcProductId = product.metadata?.wcProductId;
if (!wcProductId) continue;
await wc.put(`products/${wcProductId}`, {
stock_quantity: product.available,
manage_stock: true,
});
console.log(`Updated WC product ${wcProductId}: ${product.available} units`);
}
}
syncStockToWooCommerce().catch(console.error);
Step 5 — Map Products Between Systems
Store the ECOSIRE Product ID in WooCommerce product meta:
// Store ECOSIRE product ID when creating products
update_post_meta($wc_product_id, '_ecosire_product_id', $ecosire_product_id);
// Retrieve during order sync
$ecosire_id = get_post_meta($product_id, '_ecosire_product_id', true);
Step 6 — Verify the Integration
- Place a test order on WooCommerce.
- Confirm the order appears in ECOSIRE → Sales → Orders within 30 seconds.
- Check the customer was created in ECOSIRE → Contacts.
- Update stock in ECOSIRE and confirm WooCommerce product page shows updated inventory after the next sync cycle.
Troubleshooting
| Issue | Solution |
|---|---|
| Webhook not reaching ECOSIRE | Verify WordPress site has SSL; check WC Webhook delivery log |
_ecosire_product_id missing | Run a one-time product mapping import |
| Stock not updating | Confirm cron job is running; check for PHP memory limit issues |
| 401 from ECOSIRE | Verify ECOSIRE_API_KEY constant is defined in wp-config.php |
Next Steps
- Inventory Sync Guide — Multi-channel inventory management
- Zapier Integration — No-code automation alternative
- Contacts API — Contact management reference