Solution:
Use WordPress current_time() function which retrieves the current time based on specified type.
From that point on you can further customize your code to suit your needs, so you get:
function action_woocommerce_before_order_notes( $checkout ) {
// Open and close time
$open_time = strtotime('11:30');
$close_time = strtotime('22:00');
// Current time
$current_time = current_time( 'timestamp' );
// Closed
if( $current_time > $close_time || $current_time <= $open_time ) {
// Default value
$options['closed'] = __( 'Closed', 'woocommerce');
} else {
// Default value
$options[''] = __( 'As soon as possible', 'woocommerce');
// As soon as possible
$asa_possible = strtotime( '+1 hour', $current_time );
// Round to next 15 minutes (15 * 60 seconds)
$asa_possible = ceil( $asa_possible / ( 15 * 60 ) ) * ( 15 * 60);
// Add a new option every 15 minutes
while( $asa_possible <= $close_time && $asa_possible >= $open_time ) {
$value = date( 'H:i', $asa_possible );
$options[$value] = $value;
// Add 15 minutes
$asa_possible = strtotime( '+15 minutes', $asa_possible );
}
}
// Add field
woocommerce_form_field( 'delivery_time', array(
'type' => 'select',
'class' => array( 'wps-drop' ),
'label' => __('Desired delivery time', 'woocommerce' ),
'options' => $options,
), $checkout->get_value( 'delivery_time' ));
}
add_action( 'woocommerce_before_order_notes', 'action_woocommerce_before_order_notes', 10, 1 );