How to Add a Custom Checkout Field

Let’s consider you need to add a custom checkout field at the WooCommerce Checkout page. For example, it is probably a consumer licence number. Ideally, this may be some thing that should display above the checkout order notes. So, here’s the way you do it.

add_action( 'woocommerce_before_order_notes', 'codeithub_add_custom_checkout_field' );
  
function codeithub_add_custom_checkout_field( $checkout ) { 
   $current_user = wp_get_current_user();
   $saved_license_no = $current_user->license_no;
   woocommerce_form_field( 'license_no', array(        
      'type' => 'text',        
      'class' => array( 'form-row-wide' ),        
      'label' => 'License Number',        
      'placeholder' => 'CA12345678',        
      'required' => true,        
      'default' => $saved_license_no,        
   ), $checkout->get_value( 'license_no' ) ); 
}

Before:

See also  Remove the state field in the WooCommerce Checkout
Checkout Page

After:

Custom Checkout Field

Leave a Reply

Your email address will not be published. Required fields are marked *