Я поместил следующий код в мои functions.php.
И я хотел бы получить некоторые конкретные поля из новой учетной записи пользователя, которая была создана Woocommerce / Wordpress.
Ноэлектронная почта (для тестирования) не отправляется мне?Кто-нибудь знает, почему это происходит?Я думаю, что это как-то связано с классом / функциями, используемыми для получения определенных полей.
Я хочу, чтобы следующие поля отправлялись по электронной почте: имя пользователя, пароль, название компании, адрес электронной почты, первый и последнийname
И причина, по которой я хочу отправить это по электронной почте мне, состоит в том, чтобы просто проверить и проверить, все ли полевые работы.
Когда я вижу, что все работает, получая письмо, яхотел бы заменить функцию электронной почты на пост-запрос к стороннему API, чтобы я мог создать точно такую же учетную запись пользователя на стороннем веб-сайте, который не встроен в Wordpress.
Но пока главная проблема заключается вэлектронное письмо не отправляется.Это имеет отношение к Классу?
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}\n\n";
$message .= "Here are your login details for {$customer->first_name} {$customer->last_name}\n\n";
$message .= "Your company is: {$customer->company}\n\n";
$message .= "Your username is: {$this->credentials['email']}\n\n";
$message .= "Your password is: {$this->credentials['password']}\n\n";
$message .= "Your email is: {$this->credentials['email']}\n\n";
$message .= "Your role is: {$customer->role}\n\n";
$headers = array();
add_filter( 'wp_mail_content_type', function( $content_type ) {return 'text/html';});
$headers[] = 'From: My Wordpress Website <info@mydomain.com>'."\r\n";
wp_mail( $email, $subject, $message, $headers);
// Reset content-type to avoid conflicts
remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
}
}