Some WooCommerce shop owners require cut off times for delivery times during their checkout process. By that for example, a store owner can specify a time when next day deliveries are no longer possible. Maybe because of packing times or other various reasons. When using our WooCommerce Delivery plugin, cut off times are possible by using the hook “woocommerce_delivery_time_slots_ajax_options”. Below you can see an example code:
add_filter('woocommerce_delivery_time_slots_ajax_options', function($deliveryTimeOptions, $selectedDateObject, $currentDate) { $cutOffTime = '09:00'; $tomorrowDate = new DateTime('tomorrow'); $tomorrowDateFormatted = $tomorrowDate->format('Y-m-d'); $selectedDateFormatted = $selectedDateObject->format('Y-m-d'); if($selectedDateFormatted == $tomorrowDateFormatted) { $currentDateTimeCutOff = new DateTime($cutOffTime); if($currentDate >= $currentDateTimeCutOff) { $deliveryTimeOptions = array( '' => '09 am cut off. Please select the next date.' ); } } return $deliveryTimeOptions; }, 20, 3);
Add this snippet into your child theme functions.php. It will cut off next day delivery times, when the current user time exceeds 9 am. Change 09:00 to your required time and modify the response text to your needs.
Hello,
i am using this example, just above. I just change $cutOffTime with 16h00 … and it doesn’t work. Nothing happens when changing date / hours.
Something to fix ?
Thanks !
The Real Person!
When it does not work, please submit a ticket here.
The Real Person!
hello i using this example, just above. I just change $cutOffTime with 12h00 … and it doesn’t work. Nothing happens when changing date / hours.
Something to fix ?
The Real Person!
You need to set it in the correct format like: 12:00
The Real Person!
I have tried insert the cut off time code to my functions.php, but when I want to save it, it shows “Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over http://FTP.” I need help with this ya!
The Real Person!
Please submit a ticket on our website and we will take a look.