Skip to content

Headless Embed

The Swft headless embed lets you use the Swft checkout UI on any site — React, Vue, plain HTML, Shopify headless, custom Laravel storefronts — without a WooCommerce backend. You provide the cart data; Swft handles the checkout UI, payment processing, and order confirmation.

Add the Swft embed script to your page <head>:

<script src="https://cdn.swft.co.uk/embed/v1/swft-embed.js" defer></script>

The script is ~14kb gzipped and loads asynchronously. It exposes a global SwftEmbed object once the DOM is ready.

Call init() once with your configuration:

SwftEmbed.init({
merchantKey: 'pk_swft_live_xxxxxxxxxxxxxxxx',
trigger: '#checkout-btn',
mode: 'modal', // 'modal' | 'redirect' | 'inline'
locale: 'en-GB',
currency: 'GBP',
theme: 'minimal', // matches your Swft template
onSuccess: (order) => {
console.log('Order placed:', order.id)
window.location.href = `/thank-you?order=${order.id}`
},
onError: (err) => {
console.error('Checkout error:', err)
},
})
OptionTypeDefaultDescription
merchantKeystringrequiredYour public merchant key from the dashboard
triggerstring|ElementrequiredCSS selector or DOM element that opens the checkout
modestring'modal'How the checkout renders (modal, redirect, inline)
localestring'en-GB'BCP 47 locale for the checkout UI
currencystringmerchant defaultISO 4217 currency code
themestringmerchant defaultTemplate name to render
cartobjectnullPre-set cart data (see below)
onSuccessfunctionnullCalled with the completed order object
onErrorfunctionnullCalled with an error object
onClosefunctionnullCalled when the modal is dismissed without completing

If your site has the WooCommerce Store API available (standard on WooCommerce 6.9+), Swft detects it automatically and reads the cart from /wp-json/wc/store/v1/cart on trigger. No extra configuration needed — SwftEmbed.init() without a cart option will use the Store API cart.

For non-WordPress sites, pass your cart data before the checkout opens:

SwftEmbed.setCart({
lineItems: [
{
id: 'prod_abc123',
name: 'Organic Cotton T-Shirt',
price: 2999, // pence / cents
quantity: 2,
image: 'https://example.com/img/shirt.jpg',
meta: [
{ label: 'Size', value: 'M' },
{ label: 'Colour', value: 'Forest Green' },
],
},
],
subtotal: 5998,
shipping: 299,
tax: 1259,
total: 7557,
currency: 'GBP',
})

Call setCart() whenever your cart changes (item added, quantity updated, coupon applied). Swft will use the latest cart state the next time the checkout opens.

For a fully embedded checkout (no modal), use mode: 'inline' and provide a container element:

<div id="swft-checkout"></div>
<script>
SwftEmbed.init({
merchantKey: 'pk_swft_live_xxxxxxxxxxxxxxxx',
mode: 'inline',
container: '#swft-checkout',
onSuccess: (order) => { /* handle */ },
})
</script>

The checkout renders directly into the container. Useful for dedicated checkout pages.

A typical integration for a custom PHP or Node storefront:

<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdn.swft.co.uk/embed/v1/swft-embed.js" defer></script>
</head>
<body>
<button id="checkout-btn">Checkout</button>
<script>
document.addEventListener('DOMContentLoaded', () => {
SwftEmbed.init({
merchantKey: 'pk_swft_live_xxxxxxxxxxxxxxxx',
trigger: '#checkout-btn',
mode: 'modal',
locale: 'en-GB',
currency: 'GBP',
onSuccess: (order) => {
fetch('/api/orders', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ swftOrderId: order.id, ...order }),
}).then(() => {
window.location.href = `/thank-you?ref=${order.id}`
})
},
})
// Set cart from your own state management
SwftEmbed.setCart(getCartFromLocalStorage())
})
</script>
</body>
</html>

When an order completes on a non-WooCommerce site, Swft fires a order.completed webhook to your configured endpoint:

{
"event": "order.completed",
"orderId": "swft_ord_xxxxxxxx",
"merchant": "mer_xxxxxxxx",
"customer": {
"email": "[email protected]",
"name": "Jane Smith",
"address": { ... }
},
"lineItems": [ ... ],
"total": 7557,
"currency": "GBP",
"payment": {
"method": "card",
"stripeChargeId": "ch_xxxxxxxx"
}
}

Configure your webhook URL in the dashboard under Settings > Webhooks.