WWW

Integrating WooCommerce with Your Existing Web App

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:

  1. Enable the REST API in WooCommerce:
    • Go to WooCommerce → Settings → Advanced → REST API
    • Click “Add Key”
    • Generate API keys (Consumer Key and Consumer Secret)
  2. Push products from your app:

 

/**
* WooCommerce Product Creation Example
* Using the WooCommerce REST API in Node.js
*/

// Import the WooCommerce REST API client
const WooCommerceRestApi = require("@woocommerce/woocommerce-rest-api").default;

// Configure the API client
const api = new WooCommerceRestApi({

url: "https://your-woocommerce-site.com", // Your store URL
consumerKey: "ck_your_consumer_key", // Your consumer key
consumerSecret: "cs_your_consumer_secret", // Your consumer secret
version: "wc/v3" // API version

});

// Product data to be created
const productData = {

name: "Premium Wool Sweater", // Product name
type: "simple", // Product type
regular_price: "59.99", // Base price
description: "Warm, high-quality wool sweater for winter.", // Full description
short_description: "Winter wool sweater", // Short description
categories: [ // Product categories

{
id: 9 // Category ID
}
],
images: [ // Product images
{
src: "http://example.com/sweater.jpg", // Image URL
alt: "Premium Wool Sweater" // Alt text
}
]

};

/**
* Create the product using the WooCommerce API
*/
api.post("products", productData)
.then(response => {
// Success handler
console.log("✅ Product created successfully!");
console.log("Product ID:", response.data.id);
console.log("View product:", response.data.permalink);
})
.catch(error => {
// Error handler
console.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-RPC
require_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

  1. Set up authentication between your app and WooCommerce
  2. Create product data structure in your app that maps to WooCommerce fields
  3. Implement synchronization logic:
    • Decide when to push updates (real-time, scheduled batches)
    • Handle updates vs. new products
    • Manage inventory and variations if needed
  4. Add error handling for failed syncs
  5. 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

Leave A Comment

Web with Wordpress Logo
Web with Wordpress Logo

Our purpose is to build solutions that remove barriers preventing people from doing their best work.

Cart
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare