跳到正文
DEV Community· Nasrun Nasution·· 33 分鐘前AI 評分44

如何用 Make.com 將 WooCommerce 訂單記錄到 Google Sheets,避免重複計算庫存

How to log WooCommerce orders to Google Sheets without double counting (Make.com)

AI 導讀

Make.com 可將 WooCommerce 訂單記錄到 Google Sheets,並透過只處理 processing 或 completed 訂單,避免未付款訂單扣減庫存。流程以訂單 ID 檢查是否已記錄,再逐項寫入庫存流水帳,並啟用 sequential processing,減少重複記錄。

正文

The problem

If you run a small WooCommerce store, there is a good chance a Google Sheet somewhere tracks your stock. It starts simple: an order comes in, a row goes into the sheet, a formula subtracts the quantity.

Then, a few weeks later, the sheet and the shelf disagree. The sheet says 12 black T-shirts in size M; the shelf has 10. Nobody can tell which order caused it, so someone does a manual count and overwrites the number. A month later it happens again.

Most of these mismatches come from two mistakes, and both are easy to avoid once you know where they come from. This post shows how to build an order-to-sheet flow in Make.com that avoids them, step by step, using only free building blocks.

The two rules

Rule 1: only paid orders move stock. WooCommerce creates an order the moment a customer reaches checkout, often with the status pending payment. Many of those are never paid. If your automation fires on "new order", unpaid and abandoned orders reduce stock that never left the shelf. Trigger only on the statuses that mean money arrived: usually processing (paid, not shipped yet) and completed.

Rule 2: each order is recorded exactly once. The same order passes through several statuses: pending, processing, completed. If your scenario listens for order updates, it sees the same order two or three times. Webhooks can also be delivered twice, and Make can retry a run after a temporary error. Without a check, every one of those becomes another deduction.

The fix for Rule 2 is an idempotency check: before writing anything, look up the order ID. If it is already in the sheet, stop. If it is not, write the rows. This one lookup removes the most common cause of double counting.

Building it in Make

You need a WooCommerce store with REST API keys, a Google account and a free Make account.

1. Prepare the sheet. Create two tabs:

  • Ledger, one row per stock movement: order_id, sku, quantity, status, logged_at.
  • Inventory, one row per product: sku, opening_stock, current_stock. In current_stock use a formula instead of typing numbers, for example =B2-SUMIF(Ledger!B:B, A2, Ledger!C:C).

The point of this design: you never overwrite a stock number. Every change is a ledger row, so when something looks wrong you can see exactly which order caused it.

2. Create a data store for processed orders. In Make, go to Data stores and create one called processed_orders with the order ID as the key. This is your memory of which orders are already recorded.

3. Trigger on orders. Start the scenario with the WooCommerce Watch Orders module (or a custom webhook that WooCommerce calls on order updates).

4. Filter on paid statuses. Add a filter after the trigger: status equals processing OR status equals completed. Everything else stops here. That is Rule 1.

5. Check whether the order is already recorded. Add Data store → Check the existence of a record with the order ID as the key, then a filter that continues only when the result is false. That is Rule 2.

6. Split the order into line items. Add an Iterator over the order's line_items array, so a three-product order becomes three bundles.

7. Write one ledger row per item. Add Google Sheets → Add a Row to the Ledger tab and map the order ID, the item's SKU, quantity, the order status and the current time.

8. Mark the order as recorded. Add Data store → Add/replace a record with the order ID as the key. Place it after the sheet module, so an order is only marked once its rows are actually written.

9. Turn on sequential processing. In the scenario settings, enable sequential processing so two webhooks for the same order are handled one after the other instead of at the same time.

Run a test order, change its status from processing to completed, and check the Ledger: you should see the rows once, not twice.

Edge cases worth thinking about

The simple version above fixes most problems. These are the places where it can still go wrong, and what to do about them.

A run stops halfway through a multi-item order. If the sheet module fails after writing two of three items, the order is never marked as recorded. When Make retries, all three items are written again and the first two are now doubled. A safer key is one per line item, for example orderID-lineItemID, checked and marked inside the iterator instead of once per order.

Two deliveries arrive at the same second. Without sequential processing, both runs can check the data store before either has written anything, and both continue. Keep sequential processing on.

Refunds and cancellations. Nothing here restores stock automatically, and that is deliberate: a refunded item may be damaged or never returned. Record returned stock as a new ledger row with a positive quantity once the item is actually back on the shelf. Never delete old rows; the history is what makes the sheet trustworthy.

Variations. Size and colour variations need their own SKUs (for example TEE-BLK-M and TEE-BLK-L). WooCommerce puts the variation's SKU on the line item, so if variations share one SKU, your sheet cannot tell them apart.

Unknown SKUs. If an order contains a SKU that is not in the Inventory tab, the SUMIF formula silently ignores it. Add a check (a filter or a lookup against the Inventory tab) that sends you an email instead of writing a row nobody will ever count.

Cost. Every module run uses Make credits, and the iterator multiplies them by the number of items. Check your Make plan before turning this on for a busy store.

Wrapping up

You do not need a complex inventory system to stop your stock sheet from drifting. Two rules carry most of the weight: only paid orders move stock, and each order is recorded exactly once. Build those into your automation and keep every change as a ledger row, and the next time the numbers disagree you will know which order to look at.

If you would rather not build it yourself: I packaged a tested version of this setup as the WooCommerce Stock Ledger Kit (full disclosure: I built it, with a lot of help from AI). It goes a bit further than the version above: it re-reads each order directly from WooCommerce before recording it, keeps one ledger row per line item, and sends unknown SKUs or insufficient stock to a Needs_Review tab with an email alert instead of changing stock silently. It comes with illustrated step-by-step guides in English and Indonesian, for Windows and Mac.

To be clear about what it is not: it keeps a separate stock ledger in Google Sheets and does not change WooCommerce's own stock (it is not two-way sync). You need your own Make account, and one paid order uses about 10–11 Make credits.

It is $19 on Gumroad, and the first 20 buyers get 30% off with LAUNCH30: https://automateflowlabs.gumroad.com/l/woocommerce-stock-ledger-kit/LAUNCH30

Questions about the free version are welcome in the comments too. I am happy to help you get it working either way.

來源:DEV Community · dev.to