About snippets
↑ Back to topNote: This is a Developer level doc. If you are unfamiliar with code/templates and resolving potential conflicts, select a WooExpert or Developer for assistance. We are unable to provide support for customizations under our Support Policy.
Customization
↑ Back to topMake calendar default to first available booking
↑ Back to top
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
/** | |
* Will make the Bookings calender default to the month with the first available booking. | |
*/ | |
add_filter( 'wc_bookings_calendar_default_to_current_date', '__return_false' ); |
Modify the date in a booking’s summary
↑ Back to topwc_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
/** | |
* wc_bookings_summary_list_date is used to filter a booking's summary date. | |
* This example removes the end date for a multi-day booking. | |
* | |
* @param string $booking_date The formatted date that is displayed by default. | |
* @param int $booking_start Timestamp for the booking start time/date. | |
* @param int $booking_end Timestamp for the booking end time/date. | |
* @return string The modified date string. | |
*/ | |
function modify_summary_date_20170821( $booking_date, $booking_start, $booking_end ) { | |
return date( 'F j, Y', $booking_start ); | |
} | |
add_filter( 'wc_bookings_summary_list_date', 'modify_summary_date_20170821', 10, 3 ); |

Modify when In Cart bookings expire
↑ Back to topwoocommerce_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
<?php // do not copy this line | |
/** | |
* Will change the minutes it takes an In Cart booking to expire. | |
* This example reduces the number from 60 to 30. | |
* | |
* @param int $minutes 60 is the default passed | |
* @return int The amount of minutes you'd like to have In Cart bookings expire on. | |
*/ | |
function change_incart_bookings_expiry_minutes_20170825( $minutes ) { | |
return 30; | |
} | |
add_filter( 'woocommerce_bookings_remove_inactive_cart_time', 'change_incart_bookings_expiry_minutes_20170825' ); |
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.
Enable Big Selects to fix MAX_JOIN_SIZE errors
↑ Back to top
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
/** | |
* Will enable big selects when the host has a low threshold for MAX_JOIN_SIZE. | |
* This is sometimes the case with shared hosting. | |
*/ | |
function enable_big_selects_for_bookings_20170825() { | |
global $wpdb; | |
$wpdb->query( 'SET SQL_BIG_SELECTS=1' ); | |
} | |
add_action( 'init', 'enable_big_selects_for_bookings_20170825' ); |
Automatically confirm bookings purchased via COD
↑ Back to top
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
/** | |
* Will put bookings into a Confirmed status if they were paid for via COD. | |
* | |
* @param int $order_id The order id | |
*/ | |
function set_cod_bookings_confirmed_20170825( $order_id ) { | |
// Get the order, then make sure its payment method is COD. | |
$order = wc_get_order( $order_id ); | |
if ( 'cod' !== $order->get_payment_method() ) { | |
return; | |
} | |
// Call the data store class so we can get bookings from the order. | |
$booking_data = new WC_Booking_Data_Store(); | |
$booking_ids = $booking_data->get_booking_ids_from_order_id( $order_id ); | |
// If we have bookings go through each and update the status. | |
if ( is_array( $booking_ids ) && count( $booking_ids ) > 0 ) { | |
foreach ( $booking_ids as $booking_id ) { | |
$booking = get_wc_booking( $booking_id ); | |
$booking->update_status( 'confirmed' ); | |
} | |
} | |
} | |
add_action( 'woocommerce_order_status_processing', 'set_cod_bookings_confirmed_20170825', 20 ); |
Show Dependencies tab for Bookable products with WooCommerce Product Dependencies
↑ Back to top
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
/** | |
* Will make it so the Dependencies tab shows on a Bookable product. | |
* | |
* @param array $tabs The list of tabs in a product's settings. | |
*/ | |
function add_bookable_product_to_dependencies( $tabs ) { | |
// Check to see if the class exists and if the tab is set. | |
if ( class_exists( 'WC_Product_Dependencies' ) && isset( $tabs['dependencies'] ) ) { | |
// If so, add our class for the JS hooks. | |
$tabs['dependencies']['class'][] = 'show_if_booking'; | |
} | |
return $tabs; | |
} | |
add_filter( 'woocommerce_product_data_tabs', 'add_bookable_product_to_dependencies', 999 ); |
Change date format when calendar picker is not used in front end
↑ Back to top
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
/** | |
* Will make it so that the date format when the calendar is not used is DD/MM/YYYY on a Bookable product. | |
*/ | |
add_filter( 'woocommerce_bookings_mdy_format' , '__return_false' ); |
Use Custom Application from Google Developer’s Console for Calendar Integration
↑ Back to top
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
<?php | |
/** | |
* Update Google client with your own application's cliend ID and secret from the Google Developer's Console. | |
*/ | |
add_action( | |
'woocommerce_bookings_update_google_client', | |
function ( Google_Client $client ) { | |
$client->setClientId( 'YourClientIDFromGoogleDevelopersConsole' ); | |
$client->setClientSecret( 'YourClientIDFromGoogleDevelopersConsole' ); | |
} | |
); |