JavaScript API
The Buunto widget exposes functions on window.Buunto.datePicker and dispatches events on document. Use them in your theme’s code, for example to stop a custom checkout button until a date is chosen, or to show the chosen date elsewhere on the page.
The widget loads asynchronously, so call these functions after the page has loaded, and guard against the widget not being there:
if (window.Buunto?.datePicker?.hasErrors?.()) { // The customer hasn't finished choosing.}Error check functions
Section titled “Error check functions”These functions tell you whether the customer still has to choose something. They only report a missing date or time slot when the widget asks for one, which you turn on in the Buunto app under Widget settings:
- For the date: Show an error message if a date hasn’t been selected.
- For the time slot: Show an error message if a time slot hasn’t been selected (and time slots must be enabled).
They all return false when the widget isn’t shown on the page.
hasDateError()
Section titled “hasDateError()”window.Buunto.datePicker.hasDateError();Returns true if the date is missing, false otherwise. It doesn’t change what the widget shows.
hasTimeSlotError()
Section titled “hasTimeSlotError()”window.Buunto.datePicker.hasTimeSlotError();Returns true if the time slot is missing, false otherwise. It doesn’t change what the widget shows.
hasErrors()
Section titled “hasErrors()”window.Buunto.datePicker.hasErrors();Returns true if the date or the time slot is missing (or, when the store uses them, the pickup location or the postcode check), false otherwise. It doesn’t change what the widget shows.
checkErrors()
Section titled “checkErrors()”window.Buunto.datePicker.checkErrors();Returns the same result as hasErrors(), and also shows the error messages on the widget.
getCutOffTime()
Section titled “getCutOffTime()”window.Buunto.datePicker.getCutOffTime();Returns the first available date and its cut-off time, the moment after which that date can no longer be chosen. Returns undefined until the widget has loaded. cutOffTime is in the store’s time zone, without an offset.
{ "firstAvailableDate": "2025-03-02", "cutOffTime": "2025-03-01 14:00:00"}Events
Section titled “Events”The widget dispatches custom events on document. Listen to them with document.addEventListener, by their full name: each starts with BuuntoDatePicker:, as in BuuntoDatePicker:selectionChange.
selectionChange
Section titled “selectionChange”BuuntoDatePicker:selectionChange is dispatched every time something is selected or deselected in the widget. The selection is in the event’s detail:
method:LOCAL_DELIVERY,STORE_PICKUPorSHIPPING. When the store offers a single delivery method, it’s that method.date: the date inYYYY-MM-DDformat, orundefinedwhen no date is selected.dateDisplay: the date as the widget shows it, which depends on the shop’s language, orundefinedwhen no date is selected.timeSlot: the time slot as an object, for example{ from: "12:00", to: "18:00" }, orundefinedwhen no time slot is selected.timeSlotDisplay: the time slot as the widget shows it, which depends on the shop’s language, orundefinedwhen no time slot is selected.location: the selected pickup or delivery location’s ID, for example99462742363, orundefinedwhen no location is selected. Older setups give it as an object,{ id: 99462742363 }, so read it as shown below.
document.addEventListener("BuuntoDatePicker:selectionChange", (e) => { const { method, date, dateDisplay, timeSlot, timeSlotDisplay, location } = e.detail; const locationId = typeof location === "object" ? location?.id : location; // Your code here.});cartAttributesUpdated
Section titled “cartAttributesUpdated”BuuntoDatePicker:cartAttributesUpdated is dispatched after the widget has saved the current selection to the cart. Its detail holds the same fields as selectionChange.
Use it when your code needs to run once Buunto has finished saving the date, time slot, method or location to the cart.
document.addEventListener("BuuntoDatePicker:cartAttributesUpdated", (e) => { const { method, date, dateDisplay, timeSlot, timeSlotDisplay, location } = e.detail; // Your code here.});displayErrors
Section titled “displayErrors”BuuntoDatePicker:displayErrors is dispatched every time the widget refreshes its error messages. The detail says what is missing:
hasDateError:truewhen the date is missing,falseotherwise.hasTimeSlotError:truewhen the time slot is missing,falseotherwise.
document.addEventListener("BuuntoDatePicker:displayErrors", (e) => { const { hasDateError, hasTimeSlotError } = e.detail; // Your code here.});hasErrors
Section titled “hasErrors”BuuntoDatePicker:hasErrors is dispatched on every selection change, with the same detail as displayErrors.
document.addEventListener("BuuntoDatePicker:hasErrors", (e) => { const { hasDateError, hasTimeSlotError } = e.detail; // Your code here.});Change the widget’s selection
Section titled “Change the widget’s selection”selectDate(date)
Section titled “selectDate(date)”window.Buunto.datePicker.selectDate(date);Changes the date selected in the widget. Pass a date in YYYY-MM-DD format, or undefined to clear it:
window.Buunto.datePicker.selectDate("2024-11-26");window.Buunto.datePicker.selectDate(undefined);Checkout URL
Section titled “Checkout URL”getCheckoutUrl(url)
Section titled “getCheckoutUrl(url)”window.Buunto.datePicker.getCheckoutUrl(url);Returns the URL to send the customer to checkout. When Prefill the Shipping address fields with the selected pickup location address is turned on in the Buunto app’s Locations settings and the customer chose Store pickup, the pickup location’s address is added to the URL, so checkout opens with that address filled in. Otherwise the URL comes back unchanged.
Use it when your theme sends customers to checkout from its own JavaScript instead of submitting the cart form: without it, the address can’t be prefilled. url is optional and defaults to /checkout. Its path and query parameters are kept.
const checkoutUrl = "/checkout";window.location = window.Buunto?.datePicker?.getCheckoutUrl?.(checkoutUrl) ?? checkoutUrl;The ?. and ?? keep your checkout button working if the widget isn’t loaded.