<?php | |
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, | |
], | |
] | |
); | |
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'] ); | |
} | |
}, | |
10, | |
2 | |
); | |
I added this code, but it shows me only one field for username! I want to add another one for first and last name. how can I fix this?
Please make sure that you added it correctly (e.g. via the Code Snippets plugin), when I test it locally it adds both fields https://prnt.sc/MaxfMAkQFeVg
is it possible to add other fields like birth date or phone number with this snippet?
It's possible, but further customizations would be required to validate, save and display the field values somewhere. It's possible without customizations already, but for vendors only (by adding attributes in Vendors/Attributes section).
help me to add a custom field of attaching a file as an id card (required) at the time of registration. I have applied the same method of the code given above. it works with first name and last name, but it shows an error 'id is required' even if the id file is uploaded.
i have applied this code in the child theme using code snippet
I want to add a file attachment field in the registration form, I want the user to upload his/her identity card which is mandatory at the time of registration I have applied the same method of the code given above. it works with first name and last name, but it shows an error 'id is required' even if the id file is uploaded.
please help me with this
Please try using our community forum for requests like this one, if there's no simple code snippet we can provide some guidance if you're familiar with WordPress development https://community.hivepress.io/
Thank you! Very helpful!