Integrating WooCommerce with Your Existing Web App
To integrate your existing web app with WooCommerce so you can push product data from your app to WooCommerce, you have several options:
Option 1: WooCommerce REST API (Recommended)
The most flexible and maintainable approach is using WooCommerce’s REST API:
- Enable the REST API in WooCommerce:
- Go to WooCommerce → Settings → Advanced → REST API
- Click “Add Key”
- Generate API keys (Consumer Key and Consumer Secret)
- Push products from your app:
/*** WooCommerce Product Creation Example* Using the WooCommerce REST API in Node.js*/
// Import the WooCommerce REST API clientconst WooCommerceRestApi = require("@woocommerce/woocommerce-rest-api").default;
// Configure the API clientconst api = new WooCommerceRestApi({
url: "https://your-woocommerce-site.com", // Your store URLconsumerKey: "ck_your_consumer_key", // Your consumer keyconsumerSecret: "cs_your_consumer_secret", // Your consumer secretversion: "wc/v3" // API version
});
// Product data to be createdconst productData = {
name: "Premium Wool Sweater", // Product nametype: "simple", // Product typeregular_price: "59.99", // Base pricedescription: "Warm, high-quality wool sweater for winter.", // Full descriptionshort_description: "Winter wool sweater", // Short descriptioncategories: [ // Product categories
{id: 9 // Category ID}],images: [ // Product images{src: "http://example.com/sweater.jpg", // Image URLalt: "Premium Wool Sweater" // Alt text}]
};
/*** Create the product using the WooCommerce API*/api.post("products", productData).then(response => {// Success handlerconsole.log("✅ Product created successfully!");console.log("Product ID:", response.data.id);console.log("View product:", response.data.permalink);}).catch(error => {// Error handlerconsole.error("❌ Error creating product:");console.error("Status:", error.response.status);console.error("Message:", error.response.data.message);
if (error.response.data.details) {console.error("Details:", error.response.data.details);}});
Option 2: WordPress XML-RPC API
For simpler implementations, you can use WordPress’s built-in XML-RPC API:
// Example PHP code to create product via XML-RPCrequire_once('IXR_Library.php');
$client = new IXR_Client('http://yoursite.com/xmlrpc.php');$client->query('wp.newPost', 1, // blog_id (usually 1)'username', 'password', array('post_type' => 'product','post_title' => 'New Product','post_content' => 'Product description','post_status' => 'publish'));
Option 3: Direct Database Access (Not Recommended)
While possible, directly modifying WooCommerce’s database tables is risky and not recommended for production environments.
Implementation Steps
- Set up authentication between your app and WooCommerce
- Create product data structure in your app that maps to WooCommerce fields
- Implement synchronization logic:
- Decide when to push updates (real-time, scheduled batches)
- Handle updates vs. new products
- Manage inventory and variations if needed
- Add error handling for failed syncs
- Test thoroughly before going live
Additional Considerations
- Product visibility: Products will be visible on the frontend immediately after creation unless you set status: “draft” and publish later
- Images: You’ll need to upload images to WordPress media library first
- Performance: For large catalogs, consider batch processing
- Webhooks: Set up WooCommerce webhooks if you need your app to react to store events

