In this document, you will find many useful snippets for customizing the functionality of WooCommerce Bookings. To use a snippet, you can copy the contained code into your child theme‘s functions.php file.
Note:
This is a Developer level doc. If you are unfamiliar working with code and resolving potential conflicts, we recommend you work with a Woo Agency Partner for larger projects, or find a WooCommerce developer on Codeable for smaller customizations. We are unable to provide support for customizations under ourSupport Policy.
By default the current month will be shown on the Bookings calendar for performance reasons. This will default it to the month with the first available block:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A booking’s date in its summary is able to be modified with the wc_bookings_summary_list_date filter. This filter passes three arguments, the original date string, the timestamp for the start, and the timestamp for the end.
This example will modify the date so that only the start date is returned for the summary:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When bookings are added to the cart, they are immediately created. This allows for blocks to be properly reserved on the calendar. By default, these bookings expire after 60 minutes and are deleted by a WP Cron event.
The woocommerce_bookings_remove_inactive_cart_time filter allows you to increase or decrease this time. The example below reduces the time to 30 minutes:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Note: If this time is reduced to just a few minutes, then it is possible a booking may be removed from a customer’s cart before they complete checkout. The lowest recommended time is 15 minutes.
Sometimes shared hosts have a low threshold for MAX_JOIN_SIZE, which causes problems with WooCommerce Bookings and WordPress in general. This example fixes that in most cases:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When an order is placed for a booking via COD it remains in Unpaid status. Some store owners may want to have these bookings moved to Confirmed status, this example will do that:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WooCommerce Product Dependencies is a great little extension that allows you to require one product if another is purchased. In order to get the Dependencies tab to show for Bookable products, a filter needs to be used:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
By default the fields used for a customer to enter a date if the calendar picker is not used are in MM/DD/YYYY format. If you would like to update this to DD/MM/YYYY format, this snippet can be used:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To forward booking details to an external site upon confirmation, you’ll need to make an API call to create a post on the external site. There is a WooCommerce Bookings hook to make these API calls. Please note that here we do not cover the specifics of making API calls to external sites.
The woocommerce_booking_{new_status} hook can be utilized to send booking details to an external site. This hook includes two parameters: $booking_id and the $booking object. It is triggered whenever a booking status changes.
Here’s an example of how to use this hook to pass the booking ID and booking object to a function, which can then be used to make an API call to create a post on the external site:
add_action( 'woocommerce_booking_confirmed', 'add_booking_to_other_site', 10, 2 );
function add_booking_to_other_site( $booking_id, $booking ) {
// API call here based on the received $booking_id and $booking
...
}
To use the Bookings Google Calendar Integration it is necessary to grant permissions to the official WooCommerce app in order to give your store access to your Google Calendar. If you wish to use your own app setup in the Google Developer’s Console you can do so by updating the Google client’s ID and secret with this snippet:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.