Overview
Spiffy Checkout JavaScript interface API
The JS Interface API enables you to tap into your checkout's data and modify things via custom code directly on your checkout.
checkout.ready()
All of your custom code that uses this interface needs to be wrapped in a ready call so it runs AFTER the checkout is interactable
<script>
checkout.ready(() => {
/* ...do your stuff here! */
})
</script>If the checkout is already interactable when you call ready, your function runs immediately. That makes it safe to call late: from a deferred or async script, from code added to the page after load, or from inside another ready callback.
checkout.data
This is the main way to access the current state of the checkout. Access checkout data any time within checkout.ready including inside events to inform any of your custom logic.
<script>
checkout.ready(() => {
console.log(checkout.data)
/* ...do your stuff here! */
})
</script>checkout.on()
Add event listeners to checkout events
Available Events
change:field- when a field value is changedchange:item- when an item is added/changed on the orderchange:discount- when the discount/promo code changeschange:payplan- when the selected payment plan changeschange:order- when the order changes/total is recalculatedchange:paymethod- when the selected payment method changes
checkout.set()
Change fields and selections on the checkout
Fields
name: String- field name, this is the same name that would be used to set the field via the URLvalue: String- the value to set the field to
Items
block_id: Int- block ID that this item exists on as an Option. This can be found by inspecting the block element you're looking to hideindex: Int- the index of the Item's optionstatus: Boolean- optional, default: false - whether we are adding/removing this item
Payment Plan
id: Int- optional, default: null - ID of the payment plan to select, null/undefined will set it to single-pay
Discount
code: String- optional, default: null - promo code to apply, null will remove the currently applied promo
Payment Method
method: String- payment method to selectpaypal- PayPal payment methodstripe- credit card via StripeexpressPay- ApplePay and other express pay options when available
checkout.show()/hide()
Hide and show sections, blocks, options and payment methods.
Hiding controls what the customer sees. It changes the order in exactly one case:
Hiding an option that is currently selected deselects it. The customer chose it, so leaving it on the order would bill them for a line they can no longer see or remove. Nothing is selected in its place — a block can end up with no selection, and choosing which option should be selected is yours to do with
checkout.set('item', …).Hiding a block or a section changes nothing about the order. Those are widgets rather than choices, so whatever is selected inside stays selected and is still charged.
A worked pair, locking a customer to the tier they already chose on your sales page:
Two things follow from the block's own rules rather than from hide():
Some blocks only make sense as a choice. A subscription block, for example, stops displaying once a single option is left. That option is still selected and still sold; there's just nothing left to pick.
A section with nothing visible left in it disappears too, so you don't have to hide the section separately after hiding its blocks.
A hidden block never blocks the Complete Purchase button, since the customer has no way to fill in fields they cannot see. Name, email and address are still required — those are checked when the order is submitted and the checkout will report an error — but your own custom fields are not, so a block you hide is a block whose custom fields you won't collect.
Visibility lives in the checkout's own state, so a re-render won't undo it. You can call hide() immediately inside ready(), with no wait or timeout — it is applied as soon as the checkout finishes loading. Something hidden that way can be briefly visible first, because the page arrives from the server before your code has had a say. If that matters for what you are hiding, style it out with Custom CSS as well as hiding it.
Sections
section_id
: Int- ID of the section to hide. This can be found by inspecting the section element you're looking to hide
Blocks
block_id
: Int- ID of the block to hide. This can be found by inspecting the block element you're looking to hide
Options
block_id
: Int- ID of the block to hide. This can be found by inspecting the block element you're looking to hideindexes: Int|Array- Index or array of indexes of the options you want to hide
Payment Method
method: String- payment method to hide/showpaypal- PayPal payment methodstripe- credit card via StripeexpressPay- ApplePay and other express pay options when available
Last updated