Keep Claude Away from the Charge Button in WooCommerce Checkout
The Slack message came in at 11:42 on a Thursday morning: "Did we just charge someone four times?" We were three hours into a drop day for a Fortune 500 apparel brand, and the answer was worse than four. Nine shoppers had duplicate holds on their cards, and three had duplicate captures that took a weekend of refunds to unwind.
We had added a Claude-backed assistant to the checkout. It validated addresses, suggested a size substitute when the requested one sold out, and, once the shopper confirmed, called a tool named submit_payment. The gateway timed out at eight seconds. The model received no tool result, treated the silence as failure, and retried. It did that 212 times in eleven minutes, across a few hundred concurrent sessions.
The model wasn't the root cause. It was the amplifier. The root cause was that we had let a probabilistic component sit on the path that moves money, and we had not made the money path idempotent in our own code.
What WooCommerce doesn't give you for free
Most teams assume WooCommerce handles checkout concurrency. It handles a lot, but not the part that bites you under load. Stock is decremented when an order transitions to a processing or completed status, through wc_reduce_stock_levels() and its neighbors. Adding to cart does not reserve anything. If two shoppers hold the last unit in their carts, both can reach payment, and whoever finishes second discovers the oversell after the card has already been authorized.
Options and transients look like a place to hold state, but they are not atomic primitives. Two PHP-FPM workers can read the same value, both decide it's available, and both write. On that drop, we oversold 38 units in a single afternoon, all from that window.
Inventory holds: pick a locking strategy on purpose
There are three reasonable approaches, and each one has a failure mode you should choose deliberately.
- Native WooCommerce stock management. Simple and well understood. The oversell window is the gap between add-to-cart and payment complete. Acceptable for low-velocity catalogs, painful for drops.
- Redis
SET NXwith a TTL. Fast and expressive. The failure mode is reconciliation: when Redis evicts a key or fails over, your holds and your ledger disagree, and nobody notices until the warehouse does. - A hold table with row locks in MySQL. This is what we shipped. Slower than Redis by a few milliseconds, but the hold and the stock row live in the same transactional engine.
The core of the hold looks like this:
BEGIN;SELECT stock_qty FROM wp_inv_stock WHERE sku = ? FOR UPDATE;-- if stock_qty - active_holds(sku) >= requested_qty then insert into wp_inv_holds with expires_at = NOW() + INTERVAL 10 MINUTECOMMIT;
A cron job releases expired holds every minute. Payment completion converts the hold into a stock decrement in one transaction. The important detail is that the lock is held by the database, not by a PHP process that may die halfway through a request. That single change ended the oversell problem on the next drop.
The payment call needs a key that outlives the model's enthusiasm
Here is the part most teams get wrong. They treat the idempotency key as a per-attempt value, usually a fresh UUID generated when the tool runs. Every retry then looks like a new payment intent. The gateway happily authorizes each one.
The key has to identify the purchase intent, not the attempt. We derive it in PHP, never in the model's output:
$key = hash('sha256', $orderId . '|' . $cartHash . '|' . $holdId);
Every retry, from the model, from a PHP timeout handler, or from a human clicking Pay twice, produces the same key. The gateway returns the original result. The model can retry all it wants; the second call is a read.
Model proposes, state machine disposes
I've stopped letting the model call anything that changes money or inventory directly. The model can call propose_size_swap or request_payment_review. Those tools write a proposal row. A deterministic state machine in Laravel, with explicit states like hold_placed, authorizing, authorized, and captured, decides what happens next. The model sees the current state as a tool result, so it never has to guess whether a payment went through.
This also gives you the kill switch. In the AI Showcase we run the same pattern with a budget guardrail per session and a global switch that disables model calls without touching the checkout itself. When the switch is off, checkout degrades to the plain WooCommerce flow. Shoppers lose a suggestion. Nobody loses a charge.
The numbers after the rebuild
Over the next drop, with the hold table, deterministic keys, and the model moved off the synchronous payment path:
- Oversold units: 38 down to 0.
- Duplicate payment attempts: 212 in eleven minutes down to 0 across roughly 40,000 orders in the following month.
- p95 time from Pay click to confirmation: about 2.1 seconds down to 640 milliseconds. Most of the difference was the model round trip we had been waiting on before submitting payment.
My position
The conventional pitch is that agentic checkout will handle the messy edge cases end to end. I think that's backwards for anything involving money or stock. Models are excellent at reading a messy address, explaining a substitution, or noticing that a shopper's cart looks like a gift order. They are the wrong component to decide whether a unit is reserved or a card is charged, because their failure mode is to try again with confidence.
Give the model a lane where being wrong costs a suggestion. Give the database and the payment layer the lanes where being wrong costs money, and make those lanes idempotent, locked, and boring.
The model can recommend the size, but it should never be the thing that decides whether a card gets charged.
At Champlin Enterprises, this is the kind of problem we spend most of our time on: pairing applied-AI features with the transactional plumbing they touch, so the failure modes are designed before the first drop day. If you're weighing a similar integration, our Champlin Enterprises team is glad to talk through where the lines should sit for your stack.