我正在开发Wordpress/WooCommerce扩展插件,以便在主站点(不是wp admin)上启用密码重置。我想使用标准WooCommerce邮件程序和电子邮件模板发送带有激活链接的密码重置请求电子邮件
电子邮件由函数触发
function send_activation_link() {
global $woocommerce;
if ( \'POST\' !== strtoupper( $_SERVER[ \'REQUEST_METHOD\' ] ) )
return;
if ( empty( $_POST[ \'action\' ] ) || ( \'lost-password\' !== $_POST[ \'action\' ] ) )
return;
//My other code here....
ob_start();
// Get mail template
woocommerce_get_template(\'emails/customer-reset-password-link.php\', array(
\'user_login\' => $user_login,
\'blogname\' => $blogname,
\'email_heading\' => $email_heading,
\'key\' => $key
));
// Get contents
$message = ob_get_clean();
$mailer = $woocommerce->mailer();
$mailer->send( $user_email, $subject, $message);
}
add_action( \'init\', \'send_activation_link\');
模板
emails/customer-reset-password-link.php
:
<?php
/**
* Password reset email
*/
if (!defined(\'ABSPATH\')) exit;
do_action(\'woocommerce_email_header\', $email_heading);
?>
<p>Message to user</p>
<?php
do_action(\'woocommerce_email_footer\');
?>
它工作得很好,但电子邮件没有用页眉和页脚包装,只是
Message to user
如果我修改WC_Email
使用函数初始化:
function tb_send_activation_link($user_login, $user_email) {
//My other code here....
ob_start();
// Get mail template
woocommerce_get_template(\'emails/customer-reset-password-link.php\', array(
\'user_login\' => $user_login,
\'blogname\' => $blogname,
\'email_heading\' => $email_heading,
\'key\' => $key
));
// Get contents
$message = ob_get_clean();
$this->send( $user_email, $subject, $message, $headers, $attachments );
}
然后将插件中的函数更改为:
function send_activation_link() {
global $woocommerce;
//My other code here....
$mailer = $woocommerce->mailer();
$mailer->tb_send_activation_link($user_login, $user_email);
}
add_action( \'init\', \'send_activation_link\');
它发送完整的电子邮件(用页眉和页脚包装)。
不知道我做错了什么,也不知道如何从插件发送电子邮件。我真的不想更改WooCommerce的核心代码,因此非常感谢您提供任何关于如何解决此问题的建议。
提前,谢谢。