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.

Leave a Reply

Your email address will not be published. Required fields are marked *