Woocommerce get user data for POST request

I have setup Woocommerce to automatically register a new customer when the order is completed.

Now I want to send the password and other things that has been generated to a third party using a API POST request to create the same user account.

Things I need to send from the Woocommerce generated account:

Email address (used for email and login on third party website)

First name

Last name

Password (Needs to be unhashed, same as used in new account email)

Can someone show me an example how to get this done? Or point me in to the right direction? I just can’t find anything to start with.

I thought by adding Curl to the Woocommerce thank you page webhook. But this won’t send the password unhashed, it just stay blank.

Hope someone knows an easy way to get this done.

Thanks!

PS: HERE IS THE CODE IN MY FUNCTIONS.PHP WHICH ISN’T WORKING.

I’M NOT GETTING ANY MAIL.

IS THERE A BETTER WAY?


class NewCustomerRegistration
{
private $credentials;

public function __construct()
{
// Use PHP_INT_MAX so that it is the last filter run on this data
// in case there are other filter changing the password, for example
add_filter(
'woocommerce_new_customer_data',
[$this, 'when_user_is_created'],
1,
PHP_INT_MAX
);
add_action('woocommerce_new_customer', [$this, 'when_customer_is_created']);
}

public function when_user_is_created($customerData)
{
$this->credentials = [
'email' => $customerData['user_email'],
'password' => $customerData['user_pass'],

];

return $customerData;
}

public function when_customer_is_created($customerId)
{
$customer = get_userdata($customerId);

/**
* Perform the required actions with collected data
*
* Email: $this->credentials['email']
* Password: $this->credentials['password']
* First Name: $customer->first_name
* Last Name: $customer->last_name
*/

// Testing sending email function
$subject = "Test Email with data";
$email = "info@mydomain.com";

$message = "Hello, {$customer->first_name}nn";
$message .= "Here are your login details for {$customer->first_name} {$customer->last_name}nn";
$message .= "Your company is: {$customer->company}nn";
$message .= "Your username is: {$this->credentials['email']}nn";
$message .= "Your password is: {$this->credentials['password']}nn";
$message .= "Your email is: {$this->credentials['email']}nn";
$message .= "Your role is: {$customer->role}nn";

$headers = array();

add_filter( 'wp_mail_content_type', function( $content_type ) {return 'text/html';});
$headers[] = 'From: My WordPress Website <info@mydomain.com>'."rn";
wp_mail( $email, $subject, $message, $headers);

// Reset content-type to avoid conflicts
remove_filter( 'wp_mail_content_type', 'set_html_content_type' );

}
}