I have developed some code for a similar purpose for a client. Basically, the idea is to give a choice of dates for the customer to choose in the checkout and then display it in admin Orders and optionally send the delivery date to customer by email. Here is the snippet…
/**
* Add the field to the checkout
**/
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="my_custom_checkout_field"><h2>'.__('Get delivered by').'</h2>';
woocommerce_form_field( 'my_field_name', array(
'type' => 'select',
'class' => array('my-field-class form-row-wide'),
'label' => __('Select a date'),
'placeholder' => __('Select a date'),
'options' => array(
'29-May-2021' => '29-May-2021',
'29-June-2021' => '29-June-2021'
)
), $checkout->get_value( 'my_field_name' ));
echo '</div>';
}
/**
* Update the order meta with field value
**/
add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta');
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ($_POST['my_field_name']) update_post_meta( $order_id, 'Get delivered by', esc_attr($_POST['my_field_name']));
}
/**
* Display field value on the order edition page
**/
add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
echo '<p><strong>'.__('Get delivered by ').':</strong> ' .get_post_meta( $order->id, 'Get delivered by', true ) .'</p>';
}
/**
* Add a custom field (in an order) to the emails
*/
add_filter( 'woocommerce_email_order_meta_fields', 'my_woocommerce_email_order_meta_fields', 10, 3 );
function my_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
$fields['Get delivered by'] = array(
'label' => __( 'Get delivered by' ),
'value' => get_post_meta( $order->id, 'Get delivered by', true ),
);
return $fields;
}
Put this code in functions.php file and you can customise this to suit to your needs. Hope you will find it useful.