问题描述
我正在使用 Wordpress 和 Woocommerce 构建电子商务网站.我需要网站在注册新客户帐户时向网站管理员发送通知电子邮件.我认为此功能将内置到 Woocommerce 中,因为它使用 Wordpress 用户帐户结构,并且 Wordpress 会发送新用户通知,但似乎并非如此.有谁知道我可以用来添加此功能的插件或函数?谢谢!
I am building an ecommerce site using Wordpress and Woocommerce. I need the site to send out a notification email to the site administrator when a new customer account is registered. I thought this functionality would be built into Woocommerce since it uses the Wordpress user account structure and Wordpress sends new user notifications, but it doesn't appear to be. Does anyone know of a plugin or a function I can use to add this functionality? Thanks!
推荐答案
我假设您在电子邮件中使用 html.如果您使用纯文本,则过程类似.
I'm assuming that you are using html inside emails. If you are using plain text the procedure is similar.
您需要覆盖 woocommerce 模板结构.您可以在此处找到操作方法:http://docs.woothemes.com/document/template-structure/.
You need to override the woocommerce template structure. Here you can find how: http://docs.woothemes.com/document/template-structure/.
实际上,您需要覆盖的唯一文件是 your_template_directory/woocommerce/emails/customer-new-account.php.
Actually the only file you need to override is your_template_directory/woocommerce/emails/customer-new-account.php.
在这个文件的末尾添加这行代码:
At the end of this file add this line of code:
<?php do_action( 'new_customer_registered', $user_login ); ?>
在functions.php中添加:
In functions.php add this:
function new_customer_registered_send_email_admin($user_login) {
ob_start();
do_action('woocommerce_email_header', 'New customer registered');
$email_header = ob_get_clean();
ob_start();
do_action('woocommerce_email_footer');
$email_footer = ob_get_clean();
woocommerce_mail(
get_bloginfo('admin_email'),
get_bloginfo('name').' - New customer registered',
$email_header.'<p>The user '.esc_html( $user_login ).' is registered to the website</p>'.$email_footer
);
}
add_action('new_customer_registered', 'new_customer_registered_send_email_admin');
这篇关于Woocommerce 新客户管理员通知电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!