Custom fields in Checkout not showing in Order page
-
Hi,
I added a few custom fields to my checkout page but the filled field don’t show in the Order page, once the order confirmed.
Here is my code, what am missing ?
/** * 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"><h3>' . __('Informations Passager(s)') . '</h3>'; woocommerce_form_field( 'my_field_name', array( 'type' => 'text', 'class' => array('my-field-class form-row-first'), 'label' => __('Passager 1'), 'placeholder' => __('Prénom'), 'required' => true, ), $checkout->get_value( 'my_field_name' )); woocommerce_form_field( 'my_field_name', array( 'type' => 'text', 'class' => array('my-field-class form-row-last'), 'placeholder' => __('Nom'), 'label' => __('(interlocuteur principal)'), ), $checkout->get_value( 'my_field_name' )); woocommerce_form_field( 'my_field_name', array( 'type' => 'text', 'class' => array('my-field-class form-row-wide'), 'label' => __(' '), 'placeholder' => __('Numéro de passeport / CI'), ), $checkout->get_value( 'my_field_name' )); woocommerce_form_field( 'my_field_name', array( 'type' => 'text', 'class' => array('my-field-class form-row-first'), 'label' => __('Passager 2'), 'placeholder' => __('Prénom'), 'required' => false, ), $checkout->get_value( 'my_field_name' )); woocommerce_form_field( 'my_field_name', array( 'type' => 'text', 'class' => array('my-field-class form-row-last'), 'placeholder' => __('Nom'), 'label' => __('(si applicable)'), ), $checkout->get_value( 'my_field_name' )); woocommerce_form_field( 'my_field_name', array( 'type' => 'text', 'class' => array('my-field-class form-row-wide'), 'label' => __(' '), 'placeholder' => __('Numéro de passeport / CI'), ), $checkout->get_value( 'my_field_name' )); woocommerce_form_field( 'my_field_name', array( 'type' => 'text', 'class' => array('my-field-class form-row-first'), 'label' => __('Passager 3'), 'placeholder' => __('Prénom'), 'required' => false, ), $checkout->get_value( 'my_field_name' )); woocommerce_form_field( 'my_field_name', array( 'type' => 'text', 'class' => array('my-field-class form-row-last'), 'placeholder' => __('Nom'), 'label' => __('(si applicable)'), ), $checkout->get_value( 'my_field_name' )); woocommerce_form_field( 'my_field_name', array( 'type' => 'text', 'class' => array('my-field-class form-row-wide'), 'label' => __(' '), 'placeholder' => __('Numéro de passeport / CI'), ), $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 ( ! empty( $_POST['my_field_name'] ) ) { update_post_meta( $order_id, 'Informations Passager(s)', sanitize_text_field( $_POST['my_field_name'] ) ); } } /** * 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){ echo '<p><strong>'.__('Informations Passager(s)').':</strong> ' . get_post_meta( $order->id, 'Informations Passager(s)', true ) . '</p>';
Thanks in advance
- The topic ‘Custom fields in Checkout not showing in Order page’ is closed to new replies.