WooCommerce Delivery Slots has a feature that allows you to modify the same day and next day delivery cut-off. But if you want to have different cut-off times for different shipping methods, you can achieve it with this code snippet.
Use case
If your logistics team takes at least 1 day for the delivery, you might want to disable the same day cut off at the midnight for the Flat rate shipping methods. But you would allow all the local pickup deliveries till the evening.
/**
* Iconic WDS - Conditionally modify the same/next day cut off time based on shipping methods.
*
* @return void
*/
function iconic_conditionally_modify_cutoff_time() {
global $iconic_wds;
if ( empty( $iconic_wds ) || empty( WC()->session ) ) {
return;
}
$shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
if ( ! isset( $shipping_methods[0] ) && isset( $_POST['shipping_method'][0] ) ) {
return;
}
$shipping_method = isset( $_POST['shipping_method'][0] ) ? $_POST['shipping_method'][0] : $shipping_methods[0];
// TODO modify the logic as per your requirements.
if ( false !== strpos( $shipping_method, 'local_pickup' ) ) {
// For all Local Pickups, allow till 18:00.
$iconic_wds->settings['datesettings_datesettings_sameday_cutoff'] = '18:00';
// Set empty for no cut off.
$iconic_wds->settings['datesettings_datesettings_nextday_cutoff'] = '';
} else {
// For other shipping methods, disable at mid night.
$iconic_wds->settings['datesettings_datesettings_sameday_cutoff'] = '00:00';
}
}
add_action( 'wp_loaded', 'iconic_conditionally_modify_cutoff_time', 11 );