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 ourย Support Policy.
Snippets
↑ Back to topMake calendar default to first available booking
↑ Back to topBy 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:
add_filter( 'wc_bookings_calendar_default_to_current_date', '__return_false' );
Modify the date in a booking’s summary
↑ Back to topA 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 keeps the formatted start date and removes the end date from a range. It changes the booking summary in checkout, emails, My Account, and the order admin. The formatting may include a start time, depending on the booking:
/**
* Keep the formatted start date from a booking summary.
*
* @param string $booking_date Original formatted booking date.
* @return string Booking date without the end-date span.
*/
function example_booking_summary_start_date( $booking_date ) {
$separator = ' - <span class="booking-end-date"';
$end_start = strpos( $booking_date, $separator );
return false === $end_start ? $booking_date : substr( $booking_date, 0, $end_start );
}
add_filter( 'wc_bookings_summary_list_date', 'example_booking_summary_start_date' );
Modify when In Cart bookings expire
↑ Back to topWhen 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:
/**
* Set the in-cart booking expiry to 30 minutes.
*
* @return int Expiry in minutes.
*/
function example_booking_cart_expiry() {
return 30;
}
add_filter( 'woocommerce_bookings_remove_inactive_cart_time', 'example_booking_cart_expiry' );
Warning:
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.
Enable Big Selects to fix MAX_JOIN_SIZE errors
↑ Back to topSome database hosts limit MAX_JOIN_SIZE, which can cause query errors. This example enables SQL_BIG_SELECTS for the database session on each WordPress request. Check with your host before using it, and test the impact on a staging site:
/**
* Enable large SELECT queries for the current database session.
*/
function example_enable_big_selects() {
global $wpdb;
$wpdb->query( 'SET SQL_BIG_SELECTS=1' );
}
add_action( 'init', 'example_enable_big_selects' );
Automatically confirm bookings purchased via COD
↑ Back to topFor a cash-on-delivery order in Processing, Bookings keeps the booking Unpaid. This example changes only its unpaid bookings to Confirmed; it does not record payment. Confirmation can trigger notifications and calendar synchronization. Test it on a staging site before using it:
/**
* Confirm unpaid bookings when a cash-on-delivery order is processing.
*
* @param int $order_id Order ID.
*/
function example_confirm_cod_bookings( $order_id ) {
$order = wc_get_order( $order_id );
if ( ! $order || 'cod' !== $order->get_payment_method() ) {
return;
}
$booking_ids = WC_Booking_Data_Store::get_booking_ids_from_order_id( $order_id );
foreach ( $booking_ids as $booking_id ) {
$booking = get_wc_booking( $booking_id );
if ( $booking && $booking->has_status( 'unpaid' ) ) {
$booking->update_status( 'confirmed' );
}
}
}
add_action( 'woocommerce_order_status_processing', 'example_confirm_cod_bookings', 20 );
Show Dependencies tab for Bookable products with WooCommerce Product Dependencies
↑ Back to topWooCommerce Product Dependencies lets you require one product when another is purchased. WordPress.org reports that this plugin has not been tested with the latest three major WordPress releases, so check compatibility on a staging site first. To show the Dependencies tab for bookable products, use this filter:
/**
* Show the Dependencies tab for bookable products.
*
* @param array $tabs Product data tabs.
* @return array Product data tabs.
*/
function example_booking_dependencies_tab( $tabs ) {
if ( class_exists( 'WC_Product_Dependencies' ) && isset( $tabs['dependencies'] ) ) {
$tabs['dependencies']['class'][] = 'show_if_booking';
}
return $tabs;
}
add_filter( 'woocommerce_product_data_tabs', 'example_booking_dependencies_tab', 999 );
Change date format when calendar picker is not used in front end
↑ Back to topWhen the calendar picker is not used, the order of the date fields depends on the site locale. If the fields show month before day, this snippet changes them to day before month:
add_filter( 'woocommerce_bookings_mdy_format', '__return_false' );
Additionally, Bookings has templates that can be overridden for a more customized approach.
Forward Booking Details to External Site Upon Confirmation
↑ Back to topTo 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.
The following skeleton receives the booking ID and object when a booking becomes confirmed. It does not send data until you implement the API call. Handle credentials and customer data securely, and test the integration on a staging site:
/**
* Handle a booking moving to confirmed status.
*
* @param int $booking_id Booking ID.
* @param WC_Booking $booking Booking object.
*/
function add_booking_to_other_site( $booking_id, $booking ) {
// Add your API call here using $booking_id and $booking.
}
add_action( 'woocommerce_booking_confirmed', 'add_booking_to_other_site', 10, 2 );
Use Custom Application from Google Developer’s Console for Calendar Integration
↑ Back to topTo connect using your own Google app, use the custom connection settings in Bookings > Settings > Calendar Connection. Follow the custom Google Calendar integration guide to configure the app and authorize the connection.
Enable Faster Calendar Availability Checks (Experimental)
↑ Back to topWooCommerce Bookings v3.0.0 introduces an experimental performance optimization that reduces booking availability calculation time on the first page load of bookable products, especially in stores with a large number of active bookings per product.
Note:
This experimental optimization is not intended for monthly booking durations, automatic resource assignment, or requests that include sold-out blocks. Bookings uses the extensive check when a product shares its booking allowance across resources.
The snippet enables an experimental optimization that simplifies how booking slots are calculated by skipping some of the more expensive availability checks.
add_filter( 'woocommerce_bookings_use_extensive_time_slots_check', '__return_false' );
Alternatively, limit this experimental optimization to a specific booking product to test it incrementally. Use either this example or the preceding example, not both: the preceding example applies to all products. Test availability and booking capacity on a staging site before using either example on a live store.
/**
* Use the simple availability check for one booking product.
*
* @param bool $use_extensive_check Whether to use the extensive check.
* @param WC_Product $product Booking product.
* @return bool
*/
function optimize_bookings_availability( $use_extensive_check, $product ) {
// Example: Only optimize for a specific product ID.
if ( 12345 === $product->get_id() ) {
return false;
}
return $use_extensive_check;
}
add_filter( 'woocommerce_bookings_use_extensive_time_slots_check', 'optimize_bookings_availability', 10, 2 );
Questions and support
↑ Back to topSomething missing from this documentation? Still have questions and need assistance?
- If you have a question about a specific extension or theme youโd like to purchase, contact us to get answers.
- If you already purchased this product and need some assistance, get in touch with a Happiness Engineer via our support page and select this product’s name from the Product dropdown.