Assign user role on new user registration
-
I have a virtual store with woocommerce where I use the USER REGISTRATION plugin to register new customers. This plugin allows the creation of custom fields.
I created a custom text field called “STATE REGISTRATION”. In this field the user can write something or leave it blank.My demand is that when creating a new user, wordpress will read this “STATE REGISTRATION” field and see if there is any content filled in it.
If you have something filled out, I need the user to have a second “ROLE” added to their profile.
I created this role before and it’s called “IE”.
I’m try this, but doesnt works!
add_action( 'user_registration_after_register_user_action', 'adiciona_role_ie', 9999, 3 ); function adiciona_role_ie( $valid_form_data, $form_id, $user_id ) { $billing_ie = ''; if ( isset( $valid_form_data['billing_ie'] ) && ! empty( $valid_form_data['billing_ie']->value ) ) { echo $billing_ie = $valid_form_data['billing_ie']->value; } if ( ! empty( $billing_ie ) ) { add_filter('user_registration_after_register_user_action', 'wc_assign_custom_role', 10, 1); function wc_assign_custom_role($args) { $args['role'] = 'ie'; return $args; } //update_user_meta( $user_id, 'ie', $role ); } }
The form registration: https://i.stack.imgur.com/WHtAm.png
- The topic ‘Assign user role on new user registration’ is closed to new replies.