Last active
June 28, 2024 03:13
-
-
Save solaceten/be363b9319e47dc0a5354f34131b721a to your computer and use it in GitHub Desktop.
Woocommerce bookings cut off time for daily tour
This file contains hidden or 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 Bookings: Woocommerce bookings - amend cut off time for daily tour | |
* Problem Scenario: Bike Hire bookable over several days, The default Woo Bookings cut off time for booking is midnight the day before. | |
* There's no easy way to modify this in the booking product set up, unless you change the set up to be bookable blocks of time (e.g. | |
* 8hrs at a time?) - which is fine, for some cases, however, in this case, we wanted to stay with bookable days so client can book | |
* multiple days hire if they wish, rather than multiple blocks of time. In this scenario, the cut off time for last bookings for the | |
* Daily Tour should be 8am on the day (2pm for a singular specific tour type per the ID ) - this allows for late arrivals and last | |
* minute walk ups etc. and yet, retains the Daily Tour settings. | |
* Note: this snippet will only work where the tour is set to daily blocks, not blocks of time. Min block will be 1. | |
* Requires Woocommerce Bookings plugin. | |
* I hope this helps someone. | |
* @ Thank you to @rajeshstarlite @https://github.com/rajeshstarlite | |
* | |
* ============================================================= | |
*/ | |
// set the cut off time | |
function custom_cut_off_time($bookable, $bookable_product, $resource_id, $check_date) { | |
$current_time = current_time('timestamp'); | |
$current_date = strtotime(date('Y-m-d', $current_time)); | |
if ($bookable_product->get_id() == '1234') { // add for specific booking product ID that could be different from the others | |
$cut_off_time_short = 'Y-m-d 14:00:00'; // this product ID cut off time is 2pm on the daily tour (example allows for late arrivals) | |
} else { | |
$cut_off_time_short = 'Y-m-d 08:00:00'; // new default cut off time is 8am on the daily tour (example allows for walk ins) | |
} | |
$cut_off_time = strtotime(date($cut_off_time_short, $current_time)); | |
if ($current_time > $cut_off_time && $current_date == strtotime(date('Y-m-d', $check_date))) { | |
$bookable = false; | |
} | |
return $bookable; | |
} | |
add_filter('woocommerce_bookings_is_date_bookable', 'custom_cut_off_time', 30, 4); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment