Title: WooCommerce Tutorial
Last modified: December 21, 2017

---

# WooCommerce Tutorial

 *  Resolved [LordLiverpool](https://wordpress.org/support/users/lordliverpool/)
 * (@lordliverpool)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/woocommerce-tutorial/)
 * Hello WooCommerce
 * **First Issue:**
 * I followed your tutorial:
 * [https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/](https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/)
 * I successfully added a custom field of ‘Delivery Time’ to the Checkout page.
 * But when I look at the order via WooCommerce > Orders > Edit Order
    The field
   is empty?!? (See Screenshot)
 * ![screenshot](https://i0.wp.com/snag.gy/bNA4CM.jpg?ssl=1)
 * This is your (my) 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 ) {
           if ( ! empty( $_POST['delivery_time'] ) ) {
               update_post_meta( $order_id, 'Deliver Time', sanitize_text_field( $_POST['delivery_time'] ) );
           }
       }
   
       /**
        * 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>'.__('Delivery Time').':</strong> ' . get_post_meta( $order->id, 'delivery_time', true ) . '</p>';
       }
       ```
   
 * **Second Issue:**
 * Obviously the customer would expect to see their delivery time on the Order Received
   page, otherwise it might result in an unnecessary email/phonecall,
    so what code
   do I need to make the field appear on the Order Received page please?
 * e.g. [https://example.com/checkout/order-received](https://example.com/checkout/order-received)
 * This wasn’t covered in the official tutorial.
 * Thanks in advance.

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Erina (a11n)](https://wordpress.org/support/users/eri32s98/)
 * (@eri32s98)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/woocommerce-tutorial/#post-9805378)
 * Hello there,
 * This particular forum is mostly for questions related to the free WooCommerce
   plugin and its included features and functionalities.
    For feedback on any code
   that you’ve written, it will be better to get in touch with the web developer
   community at: * [https://wordpress.stackexchange.com/](https://wordpress.stackexchange.com/)
   or [https://stackoverflow.com/](https://stackoverflow.com/) * [https://www.facebook.com/groups/advanced.woocommerce](https://www.facebook.com/groups/advanced.woocommerce)
 *  Thread Starter [LordLiverpool](https://wordpress.org/support/users/lordliverpool/)
 * (@lordliverpool)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/woocommerce-tutorial/#post-9805459)
 * [@eri32s98](https://wordpress.org/support/users/eri32s98/)
 * Thanks for replying, it’s appreciated.
 * OK I will repost in those new forums.
 * Thanks very much.
 *  [Peter Lawrenson](https://wordpress.org/support/users/lorro/)
 * (@lorro)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/woocommerce-tutorial/#post-9805791)
 * [@lordliverpool](https://wordpress.org/support/users/lordliverpool/)
    The first
   function uses “Deliver Time” as the meta key, the second uses “delivery_time”.
   The keys should be the same.
 *  Thread Starter [LordLiverpool](https://wordpress.org/support/users/lordliverpool/)
 * (@lordliverpool)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/woocommerce-tutorial/#post-9805928)
 * ![homer](https://i0.wp.com/snag.gy/pR81cd.jpg?ssl=1)
 *  Thread Starter [LordLiverpool](https://wordpress.org/support/users/lordliverpool/)
 * (@lordliverpool)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/woocommerce-tutorial/#post-9806105)
 * Changing that field made no difference 🙁
 * Delivery Time still isn’t being populated in Order Edit
 * Here’s my code:
 *     ```
       /*************************************************************************************/
   
       /* Add Delivery Time */
       /*********************/
   
       // Hook in
       add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
   
       // Our hooked in function - $fields is passed via the filter!
       function custom_override_checkout_fields( $fields ) {
   
            $fields['billing']['delivery_time'] = array(
               'type'          => 'select',
               'label'         => __('Delivery Time', 'woocommerce'),
               'placeholder'   => __('Choose a Time', 'placeholder', 'woocommerce'),
               'required'      => true,
               'class'         => array('form-row-wide'),
               'clear'         => true        
            );
   
       	$fields['billing']['delivery_time']['options'] = array(
         	    'option_1' => 'Morning: 7am-9am',
               'option_2' => 'Evening: 7pm-9pm'
       	);
   
            return $fields;
       }
   
       /**
        * Process the checkout
        */
       add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
   
       function my_custom_checkout_field_process() {
           // Check if set, if its not set add an error.
           if ( ! $_POST['delivery_time'] )
               wc_add_notice( __( 'Please choose a delivery time' ), 'error' );
       }
   
       /**
        * 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['delivery_time'] ) ) {
               update_post_meta( $order_id, 'Delivery Time', sanitize_text_field( $_POST['delivery_time'] ) );
           }
       }
   
       /**
        * 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>'.__('Delivery Time').':</strong> ' . get_post_meta( $order->id, 'delivery_time', true ) . '</p>';
       }
   
       /*************************************************************************************/
       ```
   
 * I know this sounds obvious but do I need to create a new column for Delivery 
   Time in a database table to insert the value?
 *  [Peter Lawrenson](https://wordpress.org/support/users/lorro/)
 * (@lorro)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/woocommerce-tutorial/#post-9806193)
 * No, because the order_id and the meta_key are enough to identify the relevant
   value. All sorts of odd bits of data get put in the postmeta table.
 * You still have different meta_keys in update_post_meta() and in the later get_post_meta().
 * Can’t remember why I did it, but on mine I have the update_post_meta() in the
   ‘
   woocommerce_new_order’ hook, not in the ‘woocommerce_checkout_update_order_meta’
   hook.
 * I had phpMyAdmin open at the postmeta table to make sure the value was actually
   been added.
 *  Thread Starter [LordLiverpool](https://wordpress.org/support/users/lordliverpool/)
 * (@lordliverpool)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/woocommerce-tutorial/#post-9830537)
 * [@lorro](https://wordpress.org/support/users/lorro/)
 * Sorry for the slow reply! Xmas and New Year happened.
 * Anyway I found a solution here:
 * [https://www.wpstud.io/add-custom-select-field-woocommerce-checkout-page/](https://www.wpstud.io/add-custom-select-field-woocommerce-checkout-page/)
 * If anyone else wants to add a custom field to the WooCommerce checkout then that
   tutorial pretty much covers it.
 * Cheers
 *  [Joel Williams](https://wordpress.org/support/users/joelwills/)
 * (@joelwills)
 * Automattic Happiness Engineer
 * [8 years, 4 months ago](https://wordpress.org/support/topic/woocommerce-tutorial/#post-9852383)
 * I’m glad to hear you’ve solved it! Also thanks for providing a link to help others
   in future, that’s great.
 * I’ll close this now, all the best!

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘WooCommerce Tutorial’ 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/)

## Tags

 * [custom field](https://wordpress.org/support/topic-tag/custom-field/)
 * [tutorial](https://wordpress.org/support/topic-tag/tutorial/)

 * 8 replies
 * 4 participants
 * Last reply from: [Joel Williams](https://wordpress.org/support/users/joelwills/)
 * Last activity: [8 years, 4 months ago](https://wordpress.org/support/topic/woocommerce-tutorial/#post-9852383)
 * Status: resolved