Enter your keyword


How to add Adding Registration fields to the Woocommerce Registration form

 //Add Registration fields to the form 
add_filter( 'register_form', 'adding_custom_registration_fields' );
function adding_custom_registration_fields( ) {
        echo '<div class="form-row form-row-wide"><label for="reg_role">'.__('Role', 'woocommerce').' <span class="required">*</span></label>';
        echo '<select name="wp_capabilities">
        <option value="customer">Customer</option>
        <option value="designer">Designer</option>
        echo '</div>';
//Validation registration form  after submission using the filter registration_errors
add_filter('registration_errors', 'registration_errors_validation', 10,3);
function registration_errors_validation($reg_errors, $sanitized_user_login, $user_email) {
    global $woocommerce;
    extract($_POST); // extracting $_POST into separate variables
    if($wp_capabilities == '' ) {
    $woocommerce->add_error( __( 'Please, fill in all the required fields.', 'woocommerce' ) );
    return $reg_errors;
//Updating use meta after registration successful registration
function adding_extra_reg_fields($user_id) {
// update user role using wordpress function
wp_update_user( array ('ID' => $user_id, 'role' => $wp_capabilities ) ) ;

No Comments

Add your review

Your email address will not be published.

* Feilds are Required.