Website Building » WooCommerce » How Do You Add a Note in Checkout WooCommerce?

How Do You Add a Note in Checkout WooCommerce?

Last updated on December 25, 2022 @ 10:21 am

Adding a note in checkout on WooCommerce is easy!

First, add the following code to your functions.php file:

add_action( 'woocommerce_after_order_notes', 'custom_checkout_field' );

function custom_checkout_field( $checkout ) {

  echo '<div id="custom-checkout-field">';

  WooCommerce_form_field( 'order_comments', array(
   'type'          => 'textarea',
   'class'         => array('my-field-class form-row-wide'),
   'label'         => __('Order Notes'),
   'placeholder'   => __('Notes about your order, e.g. special instructions'),
   ), $checkout->get_value( 'order_comments' ));

  echo '</div>';
}

This code adds a new field to the checkout page where customers can leave notes about their order.

PRO TIP: Adding a note in Checkout WooCommerce can be tricky and may cause unexpected results. Be sure to test thoroughly before using on a live site.

Next, add the following code to your functions.php file:

add_action( 'woocommerce_checkout_update_order_meta', 
'custom_checkout_field_update_order_meta' );
 
function custom_checkout_field_update_order_meta( $orderID ) {
    if ( ! empty( $_POST['order_comments'] ) ) {
        update_post_meta( 
        $orderID, 'Order Comments', sanitize_textarea_field( 
        $_POST['ordernotes'] ) );			
   }		
  }

This code saves the data from the custom checkout field to the order meta data.

Now when a customer adds a note to their order, you will be able to see it in the order details page and in the order admin.

Madison Geldart

Madison Geldart

Cloud infrastructure engineer and tech mess solver.