-2

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.

Mujahid007
  • 25
  • 5

1 Answers1

1

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');
}
Josh Bonnick
  • 2,281
  • 1
  • 10
  • 21
  • Hi brother, Thanks for sharing this code it helped me achieve what I was looking for. There is one problem I am getting hashed password with this code. Can you please help me with how to unhash that? – Mujahid007 Jan 26 '22 at 14:20
  • You cannot unhash the passwords stored in the database. See this answer: https://stackoverflow.com/a/24024772/14481105 – Josh Bonnick Jan 26 '22 at 14:35