woocommerce api

🔗 WooCommerce Webhook Integration Guide (Smarton)

This guide explains how to connect your WooCommerce store with the Smarton system for real-time product sync using webhooks.


📌 Webhook Endpoints

EventEndpoint URL
Product Createdhttps://domain.smarton.app/api/public/online_payments/create_woocommerce_article
Product Updatedhttps://domain.smarton.app/api/public/online_payments/update_woocommerce_article

✅ Note: Replace domain.smarton.app with your actual Smarton domain.


🛠 How to Add Webhooks in WooCommerce

  1. Log in to your WordPress Admin Panel.

  2. Go to WooCommerce > Settings > Advanced > Webhooks.

  3. Click "Add Webhook".

  4. Fill in the following details for each event:

🔁 For Product Created

  • Name: Smarton - Product Created

  • Status: Active

  • Topic: Product created

  • Delivery URL:
    https://domain.smarton.app/api/public/online_payments/create_woocommerce_article

  • Secret: (Optional, only if Smarton uses one)

  • API Version: WP REST API v3

  • Click Save Webhook

🔁 For Product Updated

  • Name: Smarton - Product Updated

  • Status: Active

  • Topic: Product updated

  • Delivery URL:
    https://domain.smarton.app/api/public/online_payments/update_woocommerce_article

  • Secret: (Optional)

  • API Version: WP REST API v3

  • Click Save Webhook


🔑 How to Connect Your WooCommerce Account to Smarton

To enable Smarton to fetch product variation details via the WooCommerce API:

  1. In the Smarton admin panel, go to Settings > Integrations > eShops

  2. Click "Add +" or edit an existing one.

  3. Fill in the fields:

    • Name: woocommerce

    • Type: woocommerce

    • Domain: https://yourstore.com/wp-json/wc/v3 (this is your WooCommerce REST API URL)

    • Token (Consumer Key): e.g., ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    • Password (Consumer Secret): e.g., cs_YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY

  4. Click Save.

These credentials are required for the Smarton system to authenticate and fetch product variations for each incoming webhook.


📤 Data Format (Webhook POST Body Example)

WooCommerce sends product data in JSON format. Example payload:

{
  "id": 1234,
  "name": "Classic Coffee Mug",
  "price": "14.99",
  "regular_price": "19.99",
  "sale_price": "14.99",
  "description": "A sturdy mug for your morning coffee.",
  "sku": "MUG001",
  "variations": [456, 457]
}
  • id is used as the external identifier (stored in altName in Smarton).

  • If sale_price differs from regular_price, the system automatically adds a discount label to the product name.

  • If variations are included, the Smarton system will fetch and sync each variation via the WooCommerce API.

  • SKU is limited to 32 characters.


✅ What Happens Next

  • On Product Created: A new product is added to your Smarton catalog.

  • On Product Updated: The existing product is updated. If it does not exist yet, it will be created automatically.

  • Variations: Synced and updated using WooCommerce API credentials provided in the Smarton EShop record.


🔒 Security Notes

  • Ensure your server accepts POST requests from WooCommerce (check firewall, security plugins, etc.).

  • You may optionally configure a shared webhook secret in both WooCommerce and Smarton to validate requests.

  • Smarton supports signature verification upon request.


🔁 Periodic Stock Synchronization with WooCommerce

Smarton allows you to automatically synchronize stock levels from Smarton orders back to WooCommerce using periodic listeners.

This is useful when product quantities need to be deducted in WooCommerce after sales are finalized in Smarton.


🧭 How to Enable Automatic Sync (Pro version only)

⚠️ This feature is available only to users of the paid Smarton version.

  1. Log in to your Smarton back office.

  2. Navigate to:
    Staff → Notifications → Periodic Listeners.

  3. Click the ➕ Add Listener button.

  4. In the first screen:

    • Name: Choose a recognizable name, e.g., WooCommerce Stock Sync.

    • Action: Select WoocommerceSynchronizationAction from the dropdown.

  5. In the second screen:

    • Set how frequently you want the synchronization to run (e.g., every 30 minutes).

    • Fill in the required WooCommerce API configuration:

      • consumerKey: Your WooCommerce REST API Consumer Key

      • consumerSecret: Your Consumer Secret

      • apiUrl: Your WooCommerce API base URL (e.g. https://yourstore.com)

      • syncPeriodMinutes: How many past minutes to check for new orders (e.g., 30)

  6. Save the listener. It will automatically run based on the interval you specified.


🔄 What This Does

Every time the listener runs, Smarton:

  • Finds completed orders from the past X minutes.

  • For each product in the order:

    • Finds the matching product in WooCommerce (by altName).

    • Deducts the sold quantity from WooCommerce’s stock.

    • Updates the Smarton order product with a synced quantity and clears any sync error.

  • Logs any synchronization error (like missing WooCommerce product).


📌 Example Configuration

FieldValue
consumerKeyck_XXXXXXXXXXXXXXXXXXXX
consumerSecretcs_YYYYYYYYYYYYYYYYYYYY
apiUrlhttps://yourstore.com
syncPeriodMinutes30

✅ Requirements

  • Your product in Smarton must have altName set to match the WooCommerce product ID.

  • The Smarton order must be completed (finishedAt set).

  • You must be using the paid version of Smarton to enable periodic listeners.

  • Your WooCommerce product must have stock management enabled.