Jaay
September 25, 2023, 12:53pm
1
Hello,
I would like to request the phone number in the subscription form (in addition to the first and last name) I tried to add this snippet code but that doesn’t work for the phone. How to do?
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,
],
'tel' => [
'required' => true,
'_order' => 5,
],
]
);
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['tel'] ) ) {
update_user_meta( $user_id, 'tel', $values['tel'] );
}
},
10,
2
);
Hi, tel is not the correct field name
Jaay
September 26, 2023, 11:12am
3
Ok, thanks, what is the correct field name if I want required the phone number for a subscription? Maybe there is another kind of code?
Add an attributes in Vendors/Attributes section. Rename the field hp_telephone. Then change the field name to that on your code snippet. don’t use tel, I believe it is reserved & can’t be used.
Hope this helps.
1 Like
Jaay
September 28, 2023, 10:39pm
5
Hello, thanks for your answer, I tried your solution but that still doesn’t work, we use Rentalhive and I precise it could be useful for us and our customer service to have the phone number of all the users who subscribe (not only host), so I tried with user attribute too but that doesn’t work. Maybe the snippet code is not correct?
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_telephone' => [
'required' => true,
'_order' => 5,
],
]
);
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_telephone'] ) ) {
update_user_meta( $user_id, 'hp_telephone', $values['hp_telephone'] );
}
},
10,
2
);
yevhen
October 3, 2023, 9:49pm
7
Thank you for waiting. Please try this PHP code snippet.
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_telephone' => [
'type' => 'phone',
'country' => 'FR',
'required' => true,
'_order' => 5,
],
]
);
return $form;
},
1000
);
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_telephone'] ) ) {
update_user_meta( $user_id, 'hp_hp_telephone', $values['hp_telephone'] );
}
},
1000,
2
);
1 Like
Jaay
October 4, 2023, 7:57pm
8
Thanks, that’s work just one last question about this topic, should I add a css code if I want to display “telephone” text in the form?
yevhen
October 6, 2023, 12:06am
10
Please try this PHP code snippet to add the title to the phone field.
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_telephone' => [
'label' => 'Telephone',
'type' => 'phone',
'country' => 'FR',
'required' => true,
'_order' => 5,
],
]
);
return $form;
},
1000
);
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_telephone'] ) ) {
update_user_meta( $user_id, 'hp_hp_telephone', $values['hp_telephone'] );
}
},
1000,
2
);
2 Likes
Jaay
October 6, 2023, 12:36am
11
Ok, that’s work, thanks a lot
system
Closed
November 5, 2023, 12:36am
12
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.