Delivery Time Slot Choice at Checkout
Lets customers pick a delivery time window, such as morning or evening, on the classic checkout and saves it on the order for your drivers.
Opens WPIDE on
Code
$wpide_slots = array( // Key => label.
'morning' => 'Morning (8am to 12pm)',
'afternoon' => 'Afternoon (12pm to 5pm)',
'evening' => 'Evening (5pm to 9pm)',
);
add_filter( 'woocommerce_checkout_fields', function ( $fields ) use ( $wpide_slots ) {
$fields['order']['wpide_time_slot'] = array(
'type' => 'select',
'label' => 'Delivery time slot',
'required' => true,
'priority' => 6,
'options' => array( '' => 'Choose a time slot' ) + $wpide_slots,
);
return $fields;
} );
add_action( 'woocommerce_checkout_create_order', function ( $order, $data ) use ( $wpide_slots ) {
$slot = (string) ( $data['wpide_time_slot'] ?? '' );
if ( isset( $wpide_slots[ $slot ] ) ) {
$order->update_meta_data( '_wpide_time_slot', $wpide_slots[ $slot ] );
}
}, 10, 2 );
add_action( 'woocommerce_admin_order_data_after_shipping_address', function ( $order ) {
$slot = $order->get_meta( '_wpide_time_slot' );
if ( $slot ) {
printf( '<p><strong>Delivery slot:</strong> %s</p>', esc_html( $slot ) );
}
} );
add_filter( 'woocommerce_email_order_meta_fields', function ( $fields, $sent_to_admin, $order ) {
$slot = $order->get_meta( '_wpide_time_slot' );
if ( $slot ) {
$fields['wpide_time_slot'] = array( 'label' => 'Delivery slot', 'value' => $slot );
}
return $fields;
}, 10, 3 );
Notes
Edit $wpide_slots to match your delivery rounds; the chosen slot appears on the order screen and in order emails.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.