Custom field twice on register window

Hi there,
I am facing an issue where with the snippet below, instead of showing “NIF” once, it shows it twice on the registration window. Any reason why that could be?

add_filter(
	'hivepress/v1/forms/user_register',
	function ( $form ) {
		$form['fields'] = array_merge(
			$form['fields'],
			[
				'first_name' => [
					'required' => true,
					'_order'   => 1,
				],

				'last_name'  => [
					'required' => true,
					'_order'   => 2,
				],
				
				'hp_nif'  => [
					'type' => 'text',				
					'required' => true,
					'_order'   => 3,
					'label' => 'NIF',
				],
				
				'hp_cif'  => [
					'type' => 'text',				
					'required' => false,
					'_order'   => 4,
					'label' => 'CIF (si eres consultora)',
				],
				
				'hp_razon_social'  => [
					'type' => 'text',				
					'required' => false,
					'_order'   => 5,
					'label' => 'Razón social (si eres consultora)',
				],
			]
		);

		return $form;
	},
	100
);

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

		if ( isset( $values['last_name'] ) ) {
			update_user_meta( $user_id, 'last_name', $values['last_name'] );
			
		}

		if ( isset( $values['hp_nif'] ) ) {
			update_user_meta( $user_id, 'hp_nif', $values['hp_nif'] );
		}		
		
		if ( isset( $values['hp_cif'] ) ) {
			update_user_meta( $user_id, 'hp_cif', $values['hp_cif'] );
		}
	
		if ( isset( $values['hp_razon_social'] ) ) {
			update_user_meta( $user_id, 'hp_razon_social', $values['hp_razon_social'] );
		}
	},
	10,
	2
);

Hi,

There may be 2 reasons:

  • The code snippet runs twice

  • There’s another field added via the UI or another snippet, maybe it’s a custom vendor attribute?

Thanks Ihor, I figured it out.
The user attribute was marked as required on the attribute setting itself, which made it show up on the registration page. After marking it as not required it disappeared.

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