{"id":13968,"date":"2023-01-23T12:57:45","date_gmt":"2023-01-23T11:57:45","guid":{"rendered":"https:\/\/www.welaunch.io\/en\/?post_type=faq&#038;p=13968"},"modified":"2025-02-19T19:41:05","modified_gmt":"2025-02-19T18:41:05","slug":"woocommerce-delivery-cut-off-times","status":"publish","type":"faq","link":"https:\/\/www.welaunch.io\/en\/knowledge-base\/faq\/woocommerce-delivery-cut-off-times\/","title":{"rendered":"WooCommerce Delivery Cut Off Times &#038; Dates"},"content":{"rendered":"<h2>Cut off times<\/h2>\n<p>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 <a href=\"https:\/\/www.welaunch.io\/en\/product\/woocommerce-delivery\/\">WooCommerce Delivery plugin<\/a>, cut off times are possible by using the hook &#8220;woocommerce_delivery_time_slots_ajax_options&#8221;. Below you can see an example code:<\/p>\n<pre>add_filter('woocommerce_delivery_time_slots_ajax_options', function($deliveryTimeOptions, $selectedDateObject, $currentDate) {\r\n\r\n    $cutOffTime = '09:00';\r\n    $tomorrowDate = new DateTime('tomorrow');\r\n\r\n    $tomorrowDateFormatted = $tomorrowDate-&gt;format('Y-m-d');\r\n    $selectedDateFormatted = $selectedDateObject-&gt;format('Y-m-d');\r\n\r\n    if($selectedDateFormatted == $tomorrowDateFormatted) {\r\n\r\n        $currentDateTimeCutOff = new DateTime($cutOffTime);\r\n        if($currentDate &gt;= $currentDateTimeCutOff) {\r\n            $deliveryTimeOptions = array(\r\n                '' =&gt; '09 am cut off. Please select the next date.'\r\n            );\r\n        }\r\n\r\n    }\r\n\r\n    return $deliveryTimeOptions;\r\n    \r\n\r\n}, 20, 3);\r\n<\/pre>\n<p>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.<\/p>\n<h2>Cut off dates<\/h2>\n<p>To disable dates you can use one of these two filters:<\/p>\n<p>woocommerce_delivery_disabled_dates<br \/>\nwoocommerce_delivery_enabled_dates<\/p>\n<p>An example to disable delivery dates: Disable Friday, if current week wednesday 14:00 pm has passed<\/p>\n<pre>\r\nadd_filter('woocommerce_delivery_disabled_dates', function($disabledDates) {\r\n\r\n    $now = new DateTime();\r\n    $today = new DateTime();\r\n    \r\n    \/\/ Ensure 'this Wednesday' refers to the current week's Wednesday\r\n    $wednesdayCutoff = new DateTime('Wednesday this week 14:00');\r\n    \/\/ $wednesdayCutoff = new DateTime('Tuesday this week 14:00');\r\n    $friday = new DateTime('Friday this week');\r\n    \r\n    \/\/ If today is Wednesday and it's past 2 PM, or if today is after Wednesday, disable Friday\r\n    if ($now > $wednesdayCutoff) {\r\n        $disabledDates[] = $friday->format('Y-m-d');;\r\n    }\r\n\r\n    return $disabledDates;\r\n\r\n}, 10, 1);\r\n<\/pre>\n<p>An example to enabled delivery dates specifically. We use the enabledDates and remove all enabled dates past the current day + 2 days.<\/p>\n<pre>\r\n\r\nadd_filter('woocommerce_delivery_enabled_dates', function($enabledDates) {\r\n\r\n\tdate_default_timezone_set('Asia\/Jerusalem'); \/\/ Set timezone to Israel\r\n\r\n\t$now = new DateTime();\r\n\r\n    sort($enabledDates); \/\/ Ensure dates are in ascending order\r\n    $filteredEnabledDates = [];\r\n\r\n    foreach ($enabledDates as $date) {\r\n        $availableDate = new DateTime($date . ' 14:00');\r\n        $cutoff = clone $availableDate;\r\n        $cutoff->modify('-2 days');\r\n        \r\n        if ($now <= $cutoff) {\r\n            $filteredEnabledDates[] = $availableDate->format('Y-m-d');\r\n        }\r\n    }\r\n\r\n    return $filteredEnabledDates;\r\n\r\n\r\n}, 10, 1);\r\n<\/pre>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","product_cat":[],"class_list":["post-13968","faq","type-faq","status-publish","hentry","faq_topics-delivery","faq_topics-delivery-faq","faq_topics-delivery-filter-hooks"],"_links":{"self":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/faq\/13968","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/faq"}],"about":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/types\/faq"}],"author":[{"embeddable":true,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/comments?post=13968"}],"version-history":[{"count":7,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/faq\/13968\/revisions"}],"predecessor-version":[{"id":19341,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/faq\/13968\/revisions\/19341"}],"wp:attachment":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/media?parent=13968"}],"wp:term":[{"taxonomy":"product_cat","embeddable":true,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/product_cat?post=13968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}