F
F
fsb_262017-03-16 20:05:38
WordPress
fsb_26, 2017-03-16 20:05:38

How to save wordpress username in woocommerce client billing address?

Good afternoon.
Added the ability to enter a name when registering a profile in wordpress. I want the name to be saved in two places, in the username and in the name that is indicated on the checkout page in woocommerce.
Here is the code I found on the web and it allowed me to add a name to the wordpress registration page:
//1. Adding a new element to the form
add_action( 'register_form', 'myplugin_register_form' );
function myplugin_register_form() {
$first_name = ( ! empty( $_POST['first_name'] ) ) ? trim( $_POST['first_name'] ) : '';
}
//2. Add a check if this element is required
add_filter( 'registration_errors', 'myplugin_registration_errors', 10, 3 );
function myplugin_registration_errors( $errors, $sanitized_user_login, $user_email ) {
if ( empty( $_POST['first_name'] ) || ! empty( $_POST['first_name'] ) && trim( $_POST['first_name'] ) = = '' ) {
$errors->add( 'first_name_error', __( 'ERROR: You must include a first name.', 'mydomain' ) );
}
return $errors;
}
//3. Store the new field in the user's metadata
add_action( 'user_register', 'myplugin_user_register' );
function myplugin_user_register( $user_id ) {
if ( ! empty( $_POST['first_name'] ) ) {
update_user_meta( $user_id, 'first_name', trim( $_POST['first_name'] ) );
What should be added here and where exactly so that the entered name during registration is also saved in the billing address section of the woocommerce client?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question