Checkout: custom date field

In this situation we want a custom field on checkout which has a jQuery Date selector:

/**
 * enqueue jquery datepicker script
 *
 * If is not admin (backend) and the page is 
 * woocommerce checkout add the field
 */
 

 
add_action( 'wp_enqueue_scripts', 'puddinq_enabling_date_picker' );
function puddinq_enabling_date_picker() {

    // Only on front-end and checkout page
    if( is_admin() || ! is_checkout() ) return;

    // Load the datepicker jQuery-ui plugin script
    wp_enqueue_script( 'jquery-ui-datepicker' );
}

/**
 * Add the field to checkout
 *
 * echo a 
with the script, styling and field */ add_action('woocommerce_after_order_notes', 'puddinq_delivery_date_selector', 1, 1); function puddinq_delivery_date_selector($checkout) { echo '

' . __('Afleverdatum voorkeur') . '

'; echo ' '; echo ''; woocommerce_form_field('puddinq_delivery_date', array( 'type' => 'datetime', 'class' => array( 'puddinq_delivery_date_class form-row-wide'), 'label' => __('Date') , 'placeholder' => 'Select a date', 'id' => 'datepicker' ), $checkout->get_value('puddinq_delivery_date')); echo '
'; } /** * Add the field to checkout * * echo a
with the script, styling and field */ add_action('woocommerce_checkout_update_order_meta', 'puddinq_save_date_selector_meta'); function puddinq_save_date_selector_meta( $order_id ) { if ($_POST['puddinq_delivery_date']) update_post_meta( $order_id, 'puddinq_delivery_date', esc_attr($_POST['puddinq_delivery_date'])); }