In This Article
Example App: Next Booking Availability Plugin
Clone our example plugin app, explore how it's built, and play around with its design and code.
In this example, we built a plugin that users can add to their site on Wix Bookings' Service page. It displays the date of the nearest booking availability for the particular service shown on the page.
Explore the app:
- In Blocks, you can select the widget's text element to see how its design and layout are set up.
- In the code panel, you can review the widget's code, including the widget's business logic and use of APIs.
Once you clone the example app and open it in Wix Blocks, it is a fully functioning app. You can always undo or go back to a previous version if you’ve messed something up while playing around with it.
How we built it
Widget elements
- Text element (
#text1
): Displays the next availability date
Code workflow
- Handle the widget's
onPropsChanged()
event. - Retrieve the current
bookingsServiceId
from the host widget via the plugin's API. - Get the service's availability using Wix Bookings'
getServiceAvailability()
API. - Populate the widget's text element.
Head over to our tutorial and build this plugin yourself in a few simple steps.
APIs We used
Widget code
Copy
1import wixBookingsFrontend from 'wix-bookings-frontend';2
3$widget.onPropsChanged(async (oldProps, newProps) => {4 const serviceId = newProps.bookingsServiceId; // get the current service ID from the host widget5
6 let startRange = new Date();7 let endRange = new Date();8 endRange.setDate(startRange.getDate() + 365); // one year from now9 const rangeOptions = {10 startDateTime: startRange,11 endDateTime: endRange12 };13 // get the service availability for the upcoming year14 const availability = await wixBookingsFrontend.getServiceAvailability(serviceId, rangeOptions);15 const slots = availability.slots;16
17 // get the date of the first available slot18 const options = { weekday: 'long', day: 'numeric', month: 'short' };19 const firstSlotDate = slots[0].startDateTime.toLocaleDateString('en-US', options);20
21 $w('#text1').text = "Next availability: " + firstSlotDate; // set the text element's content 22});
Was this helpful?
Yes
No