Complete website in Rs. 5,000 with Free Hosting & Domain. Offer ends in  00:00:00
Back to Blog

Add Extra Input Fields In WooCommerce Registration Form

Learn how to customize your WooCommerce registration form by adding extra input fields using simple and effective code.

Oct 11, 2022 Updated: Oct 11, 2022

In the this example we will be adding a phone number field to the start of the form. It will be saved ad billing phone number. The code goes in functions.php file or in any other file that is connected to the functions.php file.

Adding input field to form

add_action('woocommerce_register_form_start', function(){
    woocommerce_form_field('billing_phone',[
        'type'=> 'tel',
        'required'=> true,
        'label'=> 'Phone',
    ], ( isset($_POST['billing_phone']) ? $_POST['billing_phone'] : '' ) );
});

Validate form input

add_action('woocommerce_register_post', function($username, $email, $errors){
    if( empty($_POST['billing_phone']) ){
        $errors->add('billing_phone_error', 'Please enter a Phone number.');
    }
}, 10, 3);

Save form input value

add_action('woocommerce_created_customer', function($customer_id){
    if( isset($_POST['billing_phone']) ){
        update_user_meta($customer_id, 'billing_phone', sanitize_text_field($_POST['billing_phone']));
    }
});

You can a more fields using this method and validate form values as per your need.

Contact

Got A Question For Us?

Feel free to ask anything directly on call or fill the form and we will contact back within few hours.