I am overriding the woocommerce admin new order template. I am looking to add the customer's username and if possible password as well. Can anyone please help me.
<?php $user_info = get_userdata(1);
echo $user_info->user_login;?>
I am currently using this code but it's not working as intended.
CodePudding user response:
You can use the $order variable inside the template which is an instance of WC_Order to obtain the user by calling the method get_user. This will return an instance of WP_User or false if they choose to not create an account.
The WP_User instance has a method called get which you can use to obtain the username, password and any other data you require.
$user = $order->get_user();
if($user){
$username = $user->get('user_login');
$password = $user->get('user_pass');
}
