We built DEV3 AI Abandoned Cart & Win-back Emails as a WooCommerce plugin in PHP with a React admin and a small dependency-free storefront script. A WP-Cron sweep every five minutes drives everything: it detects abandonment, enrols lapsed customers into win-back, prepares AI drafts ahead of their send time, sends what is due and closes finished carts.
Key design decisions
- Capture on both checkouts. The classic checkout is captured from debounced field changes; the block checkout is captured server-side from the Store API hook
woocommerce_store_api_cart_update_customer_from_request, with the same script adding consent and the browser's timezone offset. The public capture route is same-origin, rate limited and returns no personal data, so full-page caching keeps working.
- Three consent modes. Notice (default), opt-in (nothing personal is stored until the box is ticked; unticking deletes the stored cart) and none. SMS always needs its own opt-in. Every email carries a signed one-click unsubscribe link and
List-Unsubscribe headers; unsubscribed addresses are kept only as hashes.
- Sequences as a small state machine. A cart records how many steps were sent or skipped; each step is a scheduled message row. Purchases, unsubscribes and the admin's Stop action cancel what is pending, steps that cannot be sent (unapproved template, no SMS consent) are skipped with a logged reason, and an atomic option lock stops two sweeps overlapping.
- Forward-only send-time tuning. A send can only move later, never earlier, by at most a configurable number of hours, to the hour that scores best for that shopper (their own order hours, then their open and click hours, then store-wide clicks) outside quiet hours in the shopper's own timezone. The first reminder moves at most one hour.
- AI drafts behind a review gate. The Google Gemini API rewrites a template per cart from the first name and product names only. Drafts wait in a review queue with a word diff against the template. If nobody reviews one before its send time, the approved template copy goes out instead, or the message is held for a set number of hours. Only templates with auto-approve switched on send AI copy without review.
- Coupons and restore links. Each step can mint a unique WooCommerce coupon (single use, individual use, locked to the shopper's email). The recovery link carries a cart token, the message id and an HMAC, restores items, quantities and variations, applies the coupon and pre-fills the checkout.
Architecture
Carts and messages live in two custom tables; sequences, templates and suppressions in options; order links in HPOS-safe order meta. A cart becomes recovered only when its order reaches processing or completed after a reminder was sent or its link was clicked; otherwise it counts as bought anyway. The dashboard reports recovered revenue, recovery rate, a per-step funnel and top abandoned products. SMS goes through any Twilio-compatible API. Four more AI assistants (template writer, sequence builder, send-time insights, recovery insights) only ever produce drafts or read-only reports. The API client, settings, usage logging and admin kit come from a shared core used across DEV3's plugins.