name: woocommerce-order-inventory-sync description: When the user needs to process paid WooCommerce orders to calculate raw material consumption based on Bill of Materials (BOM), update inventory levels, and sync maximum producible quantities back to WooCommerce stock. This skill monitors new paid orders, retrieves SKU and quantity data, calculates material requirements from BOM data (typically stored in Google Sheets or similar), deducts consumed materials from inventory, recalculates maximum producible product quantities based on remaining materials, and updates WooCommerce product stock levels. Triggers include WooCommerce order processing, inventory management, BOM-based material calculations, stock synchronization, and production planning workflows.
Instructions
Overview
This skill automates the end-to-end process of converting paid WooCommerce orders into raw material consumption, updating inventory, and recalculating available stock based on Bill of Materials (BOM). It connects WooCommerce with Google Sheets for BOM and inventory management.
Prerequisites
- WooCommerce Connection: Configured with API access to list orders and update products.
- Google Sheets Connection: Access to a spreadsheet containing:
BOMsheet: Product_SKU, Material_Code, Material_Name, Quantity_Per_UnitMaterial_Inventorysheet: Material_Code, Material_Name, Stock_Quantity
- Configuration File: A
config.jsonfile with:spreadsheet_id: Google Sheets ID (not folder ID)bom_sheet_name: Name of BOM sheet (default: "BOM")inventory_sheet_name: Name of inventory sheet (default: "Material_Inventory")product_mapping: Mapping of product SKUs to WooCommerce product IDs
Execution Flow
Step 1: Monitor Paid Orders
- Use
woocommerce-woo_orders_listto retrieve orders with status["processing"](paid orders). - Extract from each order:
order_idline_items: For each item, extractskuandquantity- Note: The
_reduced_stockmeta indicates WooCommerce has already reduced finished product stock.
Step 2: Retrieve BOM and Inventory Data
- Read configuration from
config.jsonto get spreadsheet ID and sheet names. - Use
google_sheet-get_sheet_datato fetch:- BOM data from the specified BOM sheet
- Current inventory from the specified inventory sheet
- Validate data structure:
- BOM must have columns: Product_SKU, Material_Code, Quantity_Per_Unit
- Inventory must have columns: Material_Code, Stock_Quantity
Step 3: Calculate Material Consumption
- Aggregate total quantities needed for each product SKU across all orders.
- For each product SKU, look up its BOM entries.
- Calculate total material consumption:
material_consumption[material_code] = sum(product_quantity × quantity_per_unit)
- Log detailed consumption breakdown for verification.
Step 4: Update Raw Material Inventory
- For each material in inventory:
- Subtract consumed quantity from current stock
- Calculate new stock level
- Use
google_sheet-update_cellsto write updated inventory back to Google Sheets. - Maintain the same data structure (Material_Code, Material_Name, Stock_Quantity).
Step 5: Calculate Maximum Producible Quantities
- For each product SKU:
- For each material in its BOM:
- Calculate
max_from_material = floor(available_stock / quantity_per_unit)
- Calculate
- Determine
min(max_from_material)across all materials → maximum producible quantity - Identify the limiting material (bottleneck)
- For each material in its BOM:
- This calculation determines the actual stock that can be promised/sold.
Step 6: Sync to WooCommerce Stock
- Use
woocommerce-woo_products_batch_updateto update product stock quantities. - Update
stock_quantityfor each product based on maximum producible calculation. - Ensure
manage_stock: trueis set for each product.
Step 7: Verification and Reporting
- Fetch updated inventory from Google Sheets to confirm changes.
- Fetch updated products from WooCommerce to confirm stock levels.
- Provide a comprehensive summary including:
- Orders processed
- Material consumption
- Updated inventory levels
- Maximum producible quantities
- Updated WooCommerce stock levels
Error Handling
- Missing Configuration: Check
config.jsonexists and has required fields. - Invalid Spreadsheet ID: Verify it's a spreadsheet ID, not a folder ID.
- Missing Sheets: Verify BOM and inventory sheets exist with correct names.
- Data Validation: Check for missing SKUs in BOM, negative inventory, etc.
- API Errors: Handle WooCommerce and Google Sheets API errors gracefully.
Notes
- The skill assumes WooCommerce has already reduced finished product stock via
_reduced_stockmeta. - Decimal quantities in BOM (e.g., 0.5L of varnish) are supported.
- The limiting material calculation uses integer division (floor) for practical production planning.
- Consider running this skill on a schedule (e.g., hourly) or triggered by order status changes.