Add Phone number to the user account section, and also make few other fields mandatory

Want to add Phone number (mandatory if possible) to the user account section, and also make few other fields like First/Last name mandatory in the user account section. Can you please help me?

Hi @ishcap619,

To add the phone number field, you can create a new attribute in either Users > Attributes or Vendors > Attributes (in the backend of WP) depending on who you want to fill in the information.

The following snippet will make the First and Last name fields required.

add_filter('hivepress/v1/forms/user_register', function($form) {
    $form['fields']['first_name']['required'] = true;
    $form['fields']['last_name']['required'] = true;
    return $form;
});

add_filter('hivepress/v1/forms/user_update_profile', function($form) {
    if (isset($form['fields']['first_name'])) {
        $form['fields']['first_name']['required'] = true;
    }
    if (isset($form['fields']['last_name'])) {
        $form['fields']['last_name']['required'] = true;
    }
    return $form;
});

add_filter('hivepress/v1/forms/user_update_settings', function($form) {
    if (isset($form['fields']['first_name'])) {
        $form['fields']['first_name']['required'] = true;
        $form['fields']['first_name']['errors']['required'] = __('This field is required.', 'hivepress');
    }
    if (isset($form['fields']['last_name'])) {
        $form['fields']['last_name']['required'] = true;
        $form['fields']['last_name']['errors']['required'] = __('This field is required.', 'hivepress');
    }
    return $form;
});

add_filter(
	'hivepress/v1/forms/user_update',
	function( $form ) {
		$form['fields']['first_name']['required'] = true;
		$form['fields']['last_name']['required'] = true;

		return $form;
	},
	1000
);

I hope this helps!

Cheers,
Chris :victory_hand:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.