View Categories

Developer reference

13 min read

Tables, options, hooks, scheduled events and the HTTP surface.

Every feature in CartWin is free. There is no paid version and nothing is locked.

15.1 Requirements and layout

  • WordPress 6.5+, PHP 7.4+, WooCommerce. No other PHP extensions beyond what WordPress and WooCommerce need; mbstring is used when present (multibyte string functions).
  • Capability for all admin actions: manage_woocommerce.
  • No Composer, no external libraries. The admin UI is classic WordPress (WP_List_Table, settings API style forms), not React.

Key files (the engine’s classes, the admin screens and the assets):

cartwin/
├─ cartwin.php                      bootstrap, activation/deactivation hooks
├─ uninstall.php                    removes data when "Delete everything" is ticked
├─ readme.txt
├─ languages/                       the translations of the plugin's own texts: cartwin-<locale>.l10n.php and .mo for six languages
├─ assets/                          checkout script + stylesheet, logo
├─ includes/                        the engine
│  ├─ class-cartwin-plugin.php      autoloading, component wiring
│  ├─ class-cartwin-install.php     tables, default templates, upgrades
│  ├─ class-cartwin-settings.php    settings storage and sanitising
│  ├─ class-cartwin-capture.php     checkout capture
│  ├─ class-cartwin-scheduler.php   the engine
│  ├─ class-cartwin-data.php        database access
│  ├─ class-cartwin-rules.php       rule engine
│  ├─ class-cartwin-coupon.php      coupons
│  ├─ class-cartwin-merge-tags.php  merge tags, product table
│  ├─ class-cartwin-links.php       restore, unsubscribe, tracking
│  ├─ class-cartwin-order-watcher.php
│  ├─ class-cartwin-channel.php     channel base class
│  ├─ channels/                     email, SMS, WhatsApp
│  ├─ wc-email/                     the email object for the WooCommerce email design
│  ├─ class-cartwin-admin-promo.php the "it is free / rate it / report a problem" texts
│  ├─ class-cartwin-webhooks.php
│  ├─ class-cartwin-abilities.php
│  ├─ class-cartwin-privacy.php
│  ├─ class-cartwin-reports.php
│  ├─ class-cartwin-logger.php
│  ├─ class-cartwin-weekly-report.php
│  └─ cartwin-functions.php         helpers
└─ admin/                           admin screens, list tables, views

Classes are autoloaded: CartWin_Some_Thing → class-cartwin-some-thing.php in includes/, includes/channels/, includes/wc-email/, admin/ or admin/list-tables/.

15.2 Database tables

All tables use the site’s prefix and cartwin_ as the name. Date-times are GMT, 1970-01-01 00:00:00 means “not set”.

{prefix}cartwin_carts — one row per cart

Column Type Notes
id bigint unsigned Primary key
token char(32) Secret; identifies the visitor’s cart and signs the links. Unique
user_id bigint unsigned 0 for guests
email, phone, first_name, last_name varchar Contact details
cart_contents longtext JSON: the items
other_fields longtext JSON: billing and shipping address
cart_total, recovered_total decimal(15,4)
currency, language varchar Store currency and locale at capture
status varchar(20) normal, abandoned, completed, lost
reminded tinyint 1 once a follow-up was sent or the restore link used
planned tinyint 1 once the cart’s messages were queued
recovered tinyint 1 when a reminded customer completed the cart
recovered_order_id bigint unsigned The completing order
unsubscribed, unsubscribed_at tinyint, datetime
consent tinyint Whether consent was given
coupon_code varchar(50) The cart’s unique coupon
legacy_id varchar(64) The cart’s id in the previous plugin, when imported
cart_time, abandoned_at, completed_at datetime

{prefix}cartwin_cart_items — id, cart_id, product_id, variation_id, quantity, line_total.

{prefix}cartwin_messages — one row per follow-up

Column Notes
id, cart_id, template_id, channel template_id is 0 for imported history
title The template’s name at the time of queueing
status pending, sending, sent, failed, skipped, cancelled
scheduled_at, sent_at
note Why the message ended with its status
track_token char(32), email only: identifies opens and clicks
opened_at, open_count, clicked_at, click_count, unsubscribed_at Tracking
coupon_code, gateway_id The coupon used; the provider’s message id for SMS / WhatsApp
attempts Failed tries so far. The message is Failed once 8 are reached (3.4)

{prefix}cartwin_templates — id, channel, name, subject, body, frequency, frequency_unit, is_active, sort_order, meta (JSON), created_at, updated_at.

{prefix}cartwin_rules — id, name, is_active, priority, match_type (all / any), conditions (JSON), action, action_value (JSON), created_at, updated_at.

15.3 Options and transients

Name Kind Content
cartwin_settings option All settings (chapter 6) as one array
cartwin_db_version option Schema version
cartwin_schema_revision option Layout revision of the tables (2). Existing installations receive added columns without a version change
cartwin_templates_seeded option 1 once the default templates were inserted
cartwin_cron_hook option The schedule in use, e.g. cartwin_interval_15
cartwin_weekly_last option The week the last summary was sent
cartwin_activated_at option When the plugin was first used (for the rating suggestion)
cartwin_review_dismissed option Set when the rating suggestion was dismissed
cartwin_maintenance_done option Flag that a one-time database maintenance has run
cartwin_cron_lock transient Engine lock, 10 minutes
cartwin_flash_{user_id} transient The one-time notice after an admin action
cartwin_draft_{kind}_{user_id} transient A form draft, kept when validation fails
cartwin_rl_{md5(ip)} transient Capture rate limit, 60 seconds
cartwin_logs_purged_day transient Day the old log files were last purged

15.4 Scheduled events

Hook Schedule Does
cartwin_cron_run cartwin_interval_5 … cartwin_interval_60 (default 15) One engine pass (3.2)
cartwin_engine_soon once: a minute after sending was switched on in the settings, and at the end of each retry pause One engine pass; logged with the origin “sending switched on” in both cases

The intervals cartwin_interval_{5,10,15,30,60} are registered on cron_schedules.

15.5 Hooks

Actions

Hook Fires Parameters
cartwin_cart_captured After a cart was captured or refreshed $cart_id, $cart
cartwin_message_sent After a follow-up was sent $message, $cart, $template
cartwin_message_failed When a delivery failed $message_id, WP_Error $result
cartwin_after_cron_run After the engine ran $summary (abandoned, planned, sent, failed, lost)
cartwin_weekly_report_sent After the weekly summary was built $sent, $totals

Filters

Filter Lets you Parameters Default
cartwin_send_email Block or allow one email (staging) true, $cart, $template, $message true
cartwin_send_sms Block or allow one SMS true, $cart, $template, $message true
cartwin_send_whatsapp Block or allow one WhatsApp message true, $cart, $template, $message true
cartwin_email_headers Change the mail headers $headers, $cart, $message See 4.3
cartwin_restore_redirect Send the customer somewhere else after a restore $checkout_url, $cart, $items_added The checkout URL
cartwin_log_dir Move the activity-log folder $dir uploads/cartwin-logs
cartwin_review_url Point the rating link elsewhere $url WordPress.org reviews page
cartwin_support_email Change the support address shown in the admin $email The author’s address
cartwin_slogan Change the brand line in the admin $text Turn abandoned carts into winning checkouts.

Example — keep your own record of every sent follow-up

add_action( 'cartwin_message_sent', function ( $message, $cart, $template ) {
    error_log( sprintf( 'CartWin: cart #%d received "%s" by %s', $cart['id'], $template['name'], $message['channel'] ) );
}, 10, 3 );

Example — send the customer to the cart page after a restore

add_filter( 'cartwin_restore_redirect', function ( $checkout_url, $cart, $added ) {
    return wc_get_cart_url();
}, 10, 3 );

15.6 HTTP surface

Endpoint Method What
/?wc-ajax=cartwin_capture POST The checkout script sends cartwin_fields (JSON): email, phone, first_name, last_name, consent, phone_consent, billing{…}, shipping{…}. Replies { "ok": true, "data": { "tracked": true } }, or { "ok": false, "code": "…" } (HTTP 403 for a refused origin or rate limit)
/?cartwin_restore=<token> GET Restores the cart, redirects to the checkout
/?wcf_ac_token=… GET Restore links of CartFlows, for imported carts
/?cartwin_unsubscribe=<token>[&m=<message token>] GET, POST Unsubscribes. GET shows the confirmation page; POST answers OK (one-click unsubscribe)
/?cartwin_open=<token> GET The 1×1 tracking pixel; answers image/gif
/?cartwin_click=<token>&r=<target>&h=<signature> GET Records the click, redirects to the (signed) target
/?cartwin_sms_event=1 POST Twilio’s “A MESSAGE COMES IN” webhook; STOP replies (see below)
admin-ajax.php?action=cartwin_preview POST Admin: renders a saved email template (nonce cartwin_ajax)
admin-ajax.php?action=cartwin_product_search POST Admin: product search for the rule editor (nonce cartwin_ajax)

The plugin registers no REST route of its own, and no shortcode and no block.

The SMS reply endpoint in detail

  • Accepted only as POST, only while Provider is Twilio and an Auth Token is entered. Everything else is answered with 403 Forbidden (text/plain).
  • The request must carry X-Twilio-Signature: base64 of HMAC-SHA1 over the full URL (without the query string; a variant with it is accepted too) followed by every posted parameter as name + value, sorted by name, keyed with the Auth Token. A wrong signature is logged as a warning and answered with 403.
  • A Body that consists of STOP, UNSUBSCRIBE, CANCEL, END or QUIT (after upper-casing and removing everything but A–Z) calls CartWin_Data::unsubscribe_phone() for the normalised From number. Any other body is logged at debug level.
  • The answer is 200 with Content-Type: text/xml and an empty <Response/>, so Twilio sends nothing back to the customer.

Calls the plugin makes

To Method Purpose
https://api.twilio.com/2010-04-01/Accounts/{Account SID}/Messages.json POST, form-encoded, Basic auth (SID : token) SMS through Twilio: From, To, Body
The Gateway URL from the settings POST, JSON SMS through another gateway
https://graph.facebook.com/{API version}/{Phone number ID}/messages POST, JSON, Authorization: Bearer <token> WhatsApp messages
The three Webhook URLs POST, JSON, signed Automation events (4.12)

All calls use wp_remote_post() and therefore pass through WordPress’s pre_http_request and http_request_args filters — the place to redirect or block them on a staging site. Time-outs: 20 seconds for SMS and WhatsApp, 8 seconds for webhooks.

15.7 Abilities (WordPress 6.9+)

Ability Input Output
cartwin/get-dashboard-stats { "days": 1–366 } (default 30) days, abandoned, recovered, recovered_revenue, recovery_rate, emails_sent, open_rate, click_rate
cartwin/get-product-stats { "days": 1–366 } days, products[] with product_id, name, abandoned, recovered, lost, revenue
cartwin/get-settings {} cart_lost_minutes, cart_lost_days, emails_per_run, cron_minutes, enabled, capture_enabled, sending_enabled, gdpr_enabled, coupon_mode, sms_enabled, wa_enabled
cartwin/update-settings any of cart_lost_minutes (1–1440), cart_lost_days (1–365), sending_enabled (boolean) { "updated": [ …keys ] }

Permission: manage_woocommerce. Category: cart-recovery.

Units and types

  • recovery_rate, open_rate, click_rate are numbers in percent (44.7 = 44.7 %), not fractions.
  • recovered_revenue and revenue are plain numbers in the store’s currency, rounded to two decimals — no currency code is returned.
  • Booleans come back as real booleans; cart_lost_minutes and cart_lost_days are integers.
  • emails_sent counts email messages only.

Calling an ability from code

$stats = wp_get_ability( 'cartwin/get-dashboard-stats' )->execute( array( 'days' => 7 ) );
// array( 'days' => 7, 'abandoned' => 42, 'recovered' => 11, 'recovered_revenue' => 1287.5, … )

execute() does the checks itself, in this order: the input is validated against the schema (a number outside its range is refused before anything runs), then the permission callback is called. A caller who cannot manage WooCommerce gets a WP_Error with the code ability_invalid_permissions, and nothing is executed.

Switching the abilities off

The setting abilities_enabled (default 1) has no field in the settings screen. Switch it in code, once:

CartWin_Settings::update( array( 'abilities_enabled' => 0 ) ); // off
CartWin_Settings::update( array( 'abilities_enabled' => 1 ) ); // on again

The change is written to the activity log as “Settings changed”. Abilities are registered on wp_abilities_api_init; an older WordPress without the Abilities API registers nothing.

15.8 Conventions worth knowing

  • One open cart per visitor. Lookup order: cookie token → user id → email address.
  • Cart statuses normal → abandoned → (completed | lost); a returning shopper moves an abandoned cart back to normal.
  • reminded is never reset. It is what makes a later order count as a recovery.
  • Messages are claimed atomically before delivery (pending → sending), which makes concurrent engine runs and manual “Send now” safe.
  • A failed hand-over is retried, on every channel. deliver() turns every WP_Error from a channel into a new try — except the code blocked (a staging filter), which ends the message as skipped. The pauses come from CartWin_Scheduler::retry_delay(): 1, 5, 15, 60, 180, 720 and 1440 minutes; the count is kept in messages.attempts. While retrying the message is pending again with scheduled_at set to the end of the pause, the note Attempt n failed, retrying in m min: …, and a one-off engine run is scheduled for that moment. This includes errors that will not go away by themselves (missing provider settings, an unknown template name, an invalid JSON body): they too are tried eight times. cartwin_message_failed fires on every failed try. Queue again does not reset attempts, so after the automatic tries it yields exactly one more try.
  • Rules are evaluated twice: when a cart is planned, and again right before each send.
  • Settings are sanitised on every write, whether they come from the form or from CartWin_Settings::update().
  • Switching sending on reaches back. The settings form then unplans every abandoned cart (planned = 0) and schedules a one-off engine run a minute later (cartwin_engine_soon, logged as origin “sending switched on”). The engine plans every abandoned cart inside the “Lost after” window, whatever moment sending was switched on — sending_since is still written but no longer read. At planning, an overdue template gets now; each later overdue one keeps its spacing to the one before. Messages that already exist are never rescheduled.
  • update() is the quieter path. It changes values and logs them, but does neither the unplanning nor the extra run — the AI ability uses it, so the effect there starts at the next regular engine run.
  • The restore link is a key. It contains the cart’s secret token: anyone who holds it can restore that cart. Webhook payloads include the checkout link — give your webhook endpoints only to services you trust, and handle exported carts and logs with the same care.

Translations and the Language setting

  • The text domain cartwin ships in languages/ in both formats WordPress reads: cartwin-<locale>.l10n.php (preferred from WordPress 6.5 on) and cartwin-<locale>.mo.
  • CartWin_Settings::ui_locale() settles the language: the setting ui_language when it names one, otherwise the first supported non-English language among the WordPress profile, the site and the browser.
  • On the plugin’s own admin screens — is_admin() and ?page=cartwin — the plugin loads that file on init with load_textdomain() and filters determine_locale to the same locale. Other admin screens and the front end keep WordPress’s own locale.
  • Everywhere else WordPress loads the domain just in time, for the locale of the request. Texts the customer sees therefore follow the site language (or the page language on a multilingual site), never the Language setting.
  • At activation the folder is not registered yet, so the three default templates are seeded in English.
  • A text that is not passed through a translation function stays English in every language — as the four setting defaults do: the out-of-stock subject, the SMS opt-out hint and the two consent texts.
  • There is no switch for the setting in code other than CartWin_Settings::update( array( 'ui_language' => 'de_DE' ) ), like any other setting.

Was this helpful?

Still stuck? Write to [email protected] with a screenshot and a description.

Download CartWin — it’s free

← Previous: Troubleshooting   |