View Categories

How to set a cut-off time for ordering

If you have a certain time where customers should no longer be able to place orders for a certain day, you can use the code snippet below to set this time.

Note: For the below code snippet to work, you need to have enabled Delivery Time and created time slots for the delivery schedule. You also need to enable the option to make the Delivery time field required from the Chwazi Delivery Time settings.

The code below assumes that you only want this logic to apply to delivery orders. If you also want it to apply to pickup orders, then delete this portion of the code:

	if( $order_type === 'pickup' ){
		return $times_for_day;
	}

Code snippet:

function sl_cc_alter_times_270124($times_for_day, $date, $day_of_the_week, $order_type){
	
	if( $order_type === 'pickup' ){ // We are only applying this to delivery orders.
		return $times_for_day;
	}
	
	$current_date = current_time('Y-m-d');
	
	if( $date !== $current_date ){ // The logic should only run for the current day time slots.
		return $times_for_day;
	}
	
	// Get current time in 24hr time. This will use the timezone you've set inside WordPress settings.
	$current_time = current_time('H:i');
	
	// If the current time is 12:00 PM or more. Then we return an empty array. 
	// This causes the "No available time slots" message to show to the customer.
	// Note that the time here should be 24hr time. That means 1:00 PM would be 13:00 and so on.
	if( $current_time >= '12:00'){ 
		return array();
	};

	
	return $times_for_day;
}
add_filter('chwazi_times_for_day_after', 'sl_cc_alter_times_270124', 10, 4);

Checkout our Google Calendar Add-on

Track Your WooCommerce Orders inside Google Calendar

Learn More