Skip to content

Extensions API

The Swft Extensions API allows any WordPress plugin to pass structured data through the checkout session and interact with the checkout frontend.

Data flows in one direction: WP plugin → Swft API → Cloudflare KV → checkout frontend → WooCommerce order meta.

  1. A WP plugin hooks into swft_session_extensions and adds data to the $extensions array
  2. When a session is created, the plugin calls POST api.swft.co.uk/sessions with the extensions included in the payload
  3. The API stores the extensions in the session record and Cloudflare KV
  4. The checkout frontend reads extensions from window.__SWFT_SESSION__.extensions
  5. After payment, extensions are written to the WooCommerce order as _swft_ext_{key} meta fields

For modifying session data before it reaches the Swft API:

FilterPurpose
swft_session_extensionsPrimary extension hook — add arbitrary data to the session
swft_session_line_itemModify or exclude a single line item
swft_session_line_itemsModify all line items after the loop
swft_session_shipping_methodsModify available shipping methods
swft_session_customerModify pre-filled customer data
swft_session_totalsModify calculated totals
swft_session_payloadLast-resort: modify the complete payload

For modifying Swft Cart data:

FilterPurpose
swftcart_cart_dataModify the full cart object sent to the cart frontend
swftcart_cart_itemModify a single cart item
swftcart_modulesOverride module enable/disable state
swftcart_i18nOverride UI strings
swftcart_announcementsSet announcement bar content
swftcart_theme_varsOverride CSS custom property values
swftcart_delivery_dataSet delivery countdown data
swftcart_upsell_idsSet product IDs for the upsell module

See PHP Filters for full documentation.

Events fired by both Swft Cart and Swft Checkout as CustomEvent on document:

EventDescription
swftcart:openedCart drawer opened
swftcart:closedCart drawer closed
swftcart:fab-clickedFAB icon clicked
swftcart:cart-updatedCart contents changed
swftcart:checkoutCheckout button clicked (cancelable)
swftcart:item-removedItem removed from cart
swftcart:item-saved-for-laterItem moved to saved-for-later
swftcart:upsell-addedUpsell product added to cart
swftcart:coupon-appliedCoupon code applied
swftcart:coupon-removedCoupon code removed
swftcart:cart-sharedShare cart URL copied
swftcart:upsell-shownUpsell strip rendered
swftcheckout:readyCheckout app initialised, window.SwftCheckout available
swftcheckout:details-completeCustomer submitted the details step
swftcheckout:payment-completePayment succeeded
swftcheckout:upsell-shownPost-payment upsell rendered

See JS Events for detail shapes and examples.

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.

For a complete walkthrough of building a module using all these hooks together, see Building a Module.