Extensions API
The Swft Extensions API allows any WordPress plugin to pass structured data through the checkout session and interact with the checkout frontend.
How it works
Section titled “How it works”Data flows in one direction: WP plugin → Swft API → Cloudflare KV → checkout frontend → WooCommerce order meta.
- A WP plugin hooks into
swft_session_extensionsand adds data to the$extensionsarray - When a session is created, the plugin calls
POST api.swft.co.uk/sessionswith the extensions included in the payload - The API stores the extensions in the session record and Cloudflare KV
- The checkout frontend reads extensions from
window.__SWFT_SESSION__.extensions - After payment, extensions are written to the WooCommerce order as
_swft_ext_{key}meta fields
Available hooks
Section titled “Available hooks”PHP filters (WordPress side)
Section titled “PHP filters (WordPress side)”For modifying session data before it reaches the Swft API:
| Filter | Purpose |
|---|---|
swft_session_extensions | Primary extension hook — add arbitrary data to the session |
swft_session_line_item | Modify or exclude a single line item |
swft_session_line_items | Modify all line items after the loop |
swft_session_shipping_methods | Modify available shipping methods |
swft_session_customer | Modify pre-filled customer data |
swft_session_totals | Modify calculated totals |
swft_session_payload | Last-resort: modify the complete payload |
For modifying Swft Cart data:
| Filter | Purpose |
|---|---|
swftcart_cart_data | Modify the full cart object sent to the cart frontend |
swftcart_cart_item | Modify a single cart item |
swftcart_modules | Override module enable/disable state |
swftcart_i18n | Override UI strings |
swftcart_announcements | Set announcement bar content |
swftcart_theme_vars | Override CSS custom property values |
swftcart_delivery_data | Set delivery countdown data |
swftcart_upsell_ids | Set product IDs for the upsell module |
See PHP Filters for full documentation.
JS events (checkout frontend)
Section titled “JS events (checkout frontend)”Events fired by both Swft Cart and Swft Checkout as CustomEvent on document:
| Event | Description |
|---|---|
swftcart:opened | Cart drawer opened |
swftcart:closed | Cart drawer closed |
swftcart:fab-clicked | FAB icon clicked |
swftcart:cart-updated | Cart contents changed |
swftcart:checkout | Checkout button clicked (cancelable) |
swftcart:item-removed | Item removed from cart |
swftcart:item-saved-for-later | Item moved to saved-for-later |
swftcart:upsell-added | Upsell product added to cart |
swftcart:coupon-applied | Coupon code applied |
swftcart:coupon-removed | Coupon code removed |
swftcart:cart-shared | Share cart URL copied |
swftcart:upsell-shown | Upsell strip rendered |
swftcheckout:ready | Checkout app initialised, window.SwftCheckout available |
swftcheckout:details-complete | Customer submitted the details step |
swftcheckout:payment-complete | Payment succeeded |
swftcheckout:upsell-shown | Post-payment upsell rendered |
See JS Events for detail shapes and examples.
JavaScript API (checkout frontend)
Section titled “JavaScript API (checkout frontend)”window.SwftCheckout is available after swftcheckout:ready fires:
.addOrderRow(row)— inject a custom row into the order summary.addCustomField(field)— inject a custom form field.getExtension(key)— read data from the session extensions object
See SwftCheckout API for the full reference.
Tutorial
Section titled “Tutorial”For a complete walkthrough of building a module using all these hooks together, see Building a Module.