Solved by adding this code
/**
* 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 ) {
?>
<?php
if ( ! empty( $_POST['from_comments'] ) ) {
update_post_meta( $order_id, 'FROM', sanitize_text_field(
$_POST['from_comments']
) );
}
}
/**
* Update the order meta with field value
**/
add_action( 'woocommerce_checkout_update_order_meta',
'my_customs_checkout_field_update_order_meta' );
function my_customs_checkout_field_update_order_meta( $order_id ) {
?>
<?php
if ( ! empty( $_POST['to_comments'] ) ) {
update_post_meta( $order_id, 'TO', sanitize_text_field(
$_POST['to_comments'] )
);
}
}
/**
* Display field value on the order edit 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){
?>
<?php
echo '<p><strong>'.__('FROM').':</strong> ' . get_post_meta( $order->id, 'FROM', true
) . '</p>';
echo '<p><strong>'.__('TO').':</strong> ' . get_post_meta( $order->id, 'TO', true )
. '</p>';
}
/**
* Add the field to the checkout
*/
add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );
function my_custom_checkout_field( $checkout ) {
?>
<?php
echo '<div id="my_custom_checkout_field"><h2>' . __('TO ') . '</h2>';
woocommerce_form_field( 'from_comments', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'placeholder' => __('FROM'),
), $checkout->get_value( 'from_comments' ));
woocommerce_form_field( 'to_comments', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'placeholder' => __('TO'),
), $checkout->get_value( 'to_comments' ));
echo '</div>';
}