Ask mobile tel number in user registration form

I want users wrote their name,last name and mobile number in registration form.
I’ve found this form. Would you please update this snippet with:

Name:
Last name:
Mobile:
Whatsapp:
Email:
User Agreement confirmation check box:

add_action(
	'hivepress/v1/models/user/register',
	function( $user_id, $values ) {
		if(isset($values['first_name'], $values['last_name'])){
			update_user_meta($user_id, 'first_name', $values['first_name']);
			update_user_meta($user_id, 'last_name', $values['last_name']);
		}
	},
	10, 
	2
);

add_filter(
	'hivepress/v1/forms/user_register',
	function ( $args, $form ) {
		$args['fields'] = array_merge($args['fields'], [
			'first_name' => [
				'label' => 'First Name',
				'type'    => 'text',
				'required' => true,
				'_order' => 1,
			],
			
			'last_name' => [
				'label' => 'Last Name',
				'type'    => 'text',
				'required' => true,
				'_order' => 2,
			],
			
		]);

		return $args;
	},
	10,
	2
);

Unfortunately there’s no simple code snippet for this, it works for the first and last name fields because these fields are already available in the user settings form, they are validated and saved for users, used in emails etc. Even if you add custom fields to the initial registration form, they have to be available in the profile settings and displayed/used somewhere.

If you want to add these details for vendors (those users adding listings) it’s possible if you add custom attributes in Vendors/Attributes and mark them as Required, users will not be able to list anything without filling the required custom fields first.

1 Like

I want this field for users (who write reviews and send messages) to vendors. Actually when they want write review or send message, they must register and I think Name - Last Name - Email and Mobile number is required for users and vendors registration.

You mean:

  1. For solving this issue I must create custom attributes for mobile and Whatsapp in vendors attributes?

  2. Then I must write those customized attributes in snippet?

Yes, if you mean regular users (for vendors you can add a custom Phone attribute without code changes) then this would require advanced customizations, I guess you want not only to save the phone number but to show and use it anywhere on the site, and allow changing it - then it requires further code changes.

You can try using the same code snippet as for the first_name and last_name, but use the hp_phone field name instead. If you added a custom vendor attribute Phone with the phone field name then values will be synced, but for regular users the phone number will not be displayed anywhere and they’ll not be able to change it in the profile form. The value will be saved in the database though.