Hi. Since I couldn’t find an answer on the forum, I ask for your help.
- How can I add a field like select for vendors to the registration form? I tried to do it with the following code:
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_acctype' => [
'type' => 'select',
'required' => true,
'_order' => 3,
'label' => 'Account type',
'options' => [
'worker' => 'Worker',
'company' => 'Company',
],
],
]
);
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_acctype'] ) ) {
update_user_meta( $user_id, 'hp_acctype', $values['hp_acctype'] );
}
},
10,
2
);
The field of select type appeared, but after successful registration and going to the profile this field is set by default. Why? Can you tell me where I made a mistake?
Vendor attribute (image)
- And how can I get information about which option was selected, Worker or Company, so that in the future for example using js to show different text/images for different types of accounts?
Thanks