0

We use woocommmerce to sell online courses. also we use a plugin called "Digits" to help users easily login/register using only their mobile phone numbers and OTP sent to them as sms. So the login/register in our website, just requires entering mobile phone number (no name filed for registeration).

This process makes users able to create account and login much easier with only their number but it creates some problems.

the problems are : 1 - We need the phone number field of digits plugin, to be submitted as woocommerce phone number checkout field on every order (we have removed phone number field in woocommerce checkout because users who order something, have already registered with their phone number using digits plugin)

2 - We need name field of woocommerce checkout form to be set as users display name of wordpress account after every order.

0

1 Answer 1

0

The second part of the problem is solved by putting this code into theme's functions.php file :

// First name as default display name

add_action( 'profile_update', 'set_display_name', 10 );

function set_display_name( $user_id ) {

    $data = get_userdata( $user_id );

    if($data->first_name) {

        remove_action( 'profile_update', 'set_display_name', 10 ); // profile_update is called by wp_update_user, so we need to remove it before call, to avoid infinite recursion
        wp_update_user( 
            array (
                'ID' => $user_id, 
                'display_name' => "$data->first_name"
            ) 
        );
        add_action( 'profile_update', 'set_display_name', 10 );
    }
}

Only the first problem remains to be solved that is to add "Digits" phone number field to billing_phone field in woocommerce orders.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.