I have creatd a website for a restaurant delivery service using WordPress and WooCommerce.
Basically when the customer is checking out, he/she can choose when they want the food to be delivered. I want the select box to contain time intervals of 15 mins ranging from the current time until the close time.
The restaurant is open for deliveries between 11:30 to 22:00. The first option I want is to be "As soon as possible", and then the next option is an hour later (rounded to nearest 15mins), and then 15 mins each time. So basically something like this:
(Suppose current time is 13:55)
As soon as possible 15:00 15:15 15:30 15:45 ...and so on until close time (23:00)
Here is what I have tried so far but it only displayed whole time range. What should I do to disable past hours?
add_action('woocommerce_before_order_notes', 'wps_add_select_checkout_field');
function wps_add_select_checkout_field( $checkout ) {
woocommerce_form_field( 'delivery_time', array(
'type' => 'select',
'class' => array( 'wps-drop' ),
'label' => ( '<span class="gew-lz">Desired Delivery Time</span>'),
'options' => array(
'sofort' => 'As soon as possible',
'12:00' => '12:00',
'12:30' => '12:30',
'13:00' => '13:00',
'13:30' => '13:30',
'14:00' => '14:00',
'17:30' => '17:30',
'18:00' => '18:00',
'18:30' => '18:30',
'19:00' => '19:00',
'19:30' => '19:30',
'20:00' => '20:00',
'20:30' => '20:30',
'21:00' => '21:00',
'21:30' => '21:30',
'22:00' => '22:00',
)
),
$checkout->get_value( 'delivery_time' ));
}
All I want to disable/deactive all the past hours. When displaying on front end checkout page.
Your help will be highly appreciated.