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.

6 thoughts on “WooCommerce Delivery Cut Off Times

  1. coclico says:

    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 !

  2. stephanie

    The Real Person!

    Author stephanie acts as a real person and verified as not a bot.
    Passed all tests against spam bots. Anti-Spam by CleanTalk.
    says:

    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 ?

  3. ker xin

    The Real Person!

    Author ker xin acts as a real person and verified as not a bot.
    Passed all tests against spam bots. Anti-Spam by CleanTalk.
    says:

    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!

Leave a Reply

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