Title: Custom Checkout Fields
Last modified: August 30, 2016

---

# Custom Checkout Fields

 *  Resolved [claghorn](https://wordpress.org/support/users/claghorn/)
 * (@claghorn)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/custom-checkout-fields-1/)
 * I’m having no luck adding my Custom Checkout Fields to my order emails. I’ve 
   tried adding script to my functions.php with no success.
 * [https://wordpress.org/plugins/woocommerce/](https://wordpress.org/plugins/woocommerce/)

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/custom-checkout-fields-1/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/custom-checkout-fields-1/page/2/?output_format=md)

 *  Plugin Contributor [Claudio Sanches](https://wordpress.org/support/users/claudiosanches/)
 * (@claudiosanches)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/custom-checkout-fields-1/#post-6423472)
 * Show me the script.
 *  Thread Starter [claghorn](https://wordpress.org/support/users/claghorn/)
 * (@claghorn)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/custom-checkout-fields-1/#post-6423481)
 * /**
    * Add the field to order emails **/ add_filter(‘woocommerce_email_order_meta_keys’,‘
   my_woocommerce_email_order_meta_keys’);
 * function my_woocommerce_email_order_meta_keys( $keys ) {
    $keys[] = ‘billing_student’;
   $keys[] = ‘student_1’;
 *  return $keys;
    }
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/custom-checkout-fields-1/#post-6423483)
 * Thats out of date. See [https://gist.github.com/mikejolley/2263203](https://gist.github.com/mikejolley/2263203)
 *  Thread Starter [claghorn](https://wordpress.org/support/users/claghorn/)
 * (@claghorn)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/custom-checkout-fields-1/#post-6423488)
 * I tried with no luck:
    /** * Add the field to order emails **/ add_filter(‘woocommerce_email_order_meta_keys’,‘
   my_custom_checkout_field_order_meta_keys’);
 * function my_custom_checkout_field_order_meta_keys( $keys ) {
    $keys[] = ‘my_example’;
   return $keys; }
 * My field is named “billing_student”. I’m using Checkout Field Editor Plugin to
   create my field.
    [http://snag.gy/et4X0.jpg](http://snag.gy/et4X0.jpg)
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/custom-checkout-fields-1/#post-6423490)
 * You’re not setting the array key. Look at my snippet again. This part is wrong`
   $keys[]`
 *  Thread Starter [claghorn](https://wordpress.org/support/users/claghorn/)
 * (@claghorn)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/custom-checkout-fields-1/#post-6423491)
 * /**
    * Add the field to order emails **/ add_filter(‘woocommerce_email_order_meta_keys’,‘
   my_woocommerce_email_order_meta_keys’);
 * function my_woocommerce_email_order_meta_keys( $keys ) {
    $keys[‘Student’] = ‘
   billing_student’; return $keys; }
 * Still no bueno 🙁
 * I’m adding it in the functions.php file in my theme directory. Is that the wrong
   spot?
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/custom-checkout-fields-1/#post-6423492)
 * Ah my bad, my snippet was also out of date 🙂
 * Here is a working one from someone else I found on github you can adjust [https://gist.github.com/craigsimps/98adff30f0ac68247d59](https://gist.github.com/craigsimps/98adff30f0ac68247d59)
 *  Thread Starter [claghorn](https://wordpress.org/support/users/claghorn/)
 * (@claghorn)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/custom-checkout-fields-1/#post-6423496)
 * add_filter(‘woocommerce_email_order_meta_fields’, ‘dog_breed_checkout_field_order_meta_fields’,
   10, 3 );
    function dog_breed_checkout_field_order_meta_fields( $fields, $sent_to_admin,
   $order ) { $fields[‘billing_student’] = array( ‘label’ => __( ‘Student’ ), ‘value’
   => get_post_meta( $order->id, ‘billing_student’, true ), ); return $fields; }
 * Still no luck. Do I need to change more of the script for it to work?
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/custom-checkout-fields-1/#post-6423498)
 * Is it stored as billing_student or _billing_student? it might be the underscored
   version (hidden).
 * [https://gist.github.com/mikejolley/8f22c991e80124114d6b](https://gist.github.com/mikejolley/8f22c991e80124114d6b)
 * So in your case, meta_key would be changed to _billing_student. Check postmeta
   table in the database to confirm the key name.
 *  Thread Starter [claghorn](https://wordpress.org/support/users/claghorn/)
 * (@claghorn)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/custom-checkout-fields-1/#post-6423502)
 * changing it to _billing_student worked!!!
 * How can I add multiple fields? Thanks
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/custom-checkout-fields-1/#post-6423503)
 * Repeat this section with a different key:
 *     ```
       $fields['meta_key'] = array(
               'label' => __( 'Label' ),
               'value' => get_post_meta( $order->id, 'meta_key', true ),
           );
       ```
   
 *  Thread Starter [claghorn](https://wordpress.org/support/users/claghorn/)
 * (@claghorn)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/custom-checkout-fields-1/#post-6423507)
 * Here is the code for all 3 custom fields:
 * add_filter(‘woocommerce_email_order_meta_fields’, ‘dog_breed_checkout_field_order_meta_fields’,
   10, 3 );
    function dog_breed_checkout_field_order_meta_fields( $fields, $sent_to_admin,
   $order ) { $fields[‘_billing_student’] = array( ‘label’ => __( ‘Student’ ), ‘
   value’ => get_post_meta( $order->id, ‘_billing_student’, true ), ); $fields[‘
   _teacher’] = array( ‘label’ => __( ‘Teacher’ ), ‘value’ => get_post_meta( $order-
   >id, ‘_teacher’, true ), ); $fields[‘_grade’] = array( ‘label’ => __( ‘Grade’),‘
   value’ => get_post_meta( $order->id, ‘_grade’, true ), ); return $fields; }
 * But only Student is coming through on the emails.
 *  Thread Starter [claghorn](https://wordpress.org/support/users/claghorn/)
 * (@claghorn)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/custom-checkout-fields-1/#post-6423509)
 * It works if I change my custom field names to billing_teacher, etc.
    I’m wondering
   if the field name must already contain an “_”? It works and here is the code:
 *     ```
       add_filter('woocommerce_email_order_meta_fields', 'dog_breed_checkout_field_order_meta_fields', 10, 3 );
       function dog_breed_checkout_field_order_meta_fields( $fields, $sent_to_admin, $order ) {
           $fields['_billing_student'] = array(
                       'label' => __( 'Student' ),
                       'value' => get_post_meta( $order->id, '_billing_student', true ),
                   );
           $fields['_billing_teacher'] = array(
                       'label' => __( 'Teacher' ),
                       'value' => get_post_meta( $order->id, '_billing_teacher', true ),
                   );
           $fields['_billing_grade'] = array(
                       'label' => __( 'Grade' ),
                       'value' => get_post_meta( $order->id, '_billing_grade', true ),
                   );
           return $fields;
       }
       ```
   
 * Thanks for all your help!
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/custom-checkout-fields-1/#post-6423511)
 * If the fields are hidden (not in the custom fields section of the order), yes_
   is needed.
 *  [eolis](https://wordpress.org/support/users/eolis/)
 * (@eolis)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/custom-checkout-fields-1/#post-6423886)
 * Hi there, as this is the only place I have found this code working I thought 
   I would ask. this adds the fields to me email; now how would one specify where
   in the email?
 * EX:
 *     ```
       add_filter('woocommerce_email_order_meta_fields', 'abu_add_checkout_field_order_meta_fields', 10, 3 );
       function abu_add_checkout_field_order_meta_fields( $fields, $sent_to_admin, $order ) {
   
           // ********* These Two I want after the billing_last_name
           $fields['_billing_last_name_2'] = array(
                       'label' => __( '姓（カナ）' ),
                       'value' => get_post_meta( $order->id, '_billing_last_name_2', true ),
                   );
           $fields['_billing_first_name_2'] = array(
                       'label' => __( '名（カナ）' ),
                       'value' => get_post_meta( $order->id, '_billing_first_name_2', true ),
                   );
   
           // ********These Two I want after the shipping_last_name
           $fields['_shipping_last_name_2'] = array(
                       'label' => __( '姓（カナ）' ),
                       'value' => get_post_meta( $order->id, '_shipping_last_name_2', true ),
                   );
           $fields['_shipping_first_name_2'] = array(
                       'label' => __( '名（カナ）' ),
                       'value' => get_post_meta( $order->id, '_shipping_first_name_2', true ),
                   );
   
           // ******This one I want the billing_state or wherever, after one is done I am sure I can figure the others
           $fields['_billing_city_address_number'] = array(
                       'label' => __( '市区町村・番地' ),
                       'value' => get_post_meta( $order->id, '_billing_city_address_number', true ),
                   );
           $fields['_shipping_city_address_number'] = array(
                       'label' => __( '市区町村・番地' ),
                       'value' => get_post_meta( $order->id, '_shipping_city_address_number', true ),
                   );
           return $fields;
       }
       ```
   
 * Is there a way to add in the position in this function or will another be required
   to inject them at specific points?

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/custom-checkout-fields-1/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/custom-checkout-fields-1/page/2/?output_format=md)

The topic ‘Custom Checkout Fields’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 17 replies
 * 4 participants
 * Last reply from: [eolis](https://wordpress.org/support/users/eolis/)
 * Last activity: [9 years, 11 months ago](https://wordpress.org/support/topic/custom-checkout-fields-1/page/2/#post-6423888)
 * Status: resolved