Woocommerce New Customer Admin Notification Email

2020-02-29 03:34发布

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!

4条回答
时光不老,我们不散
2楼-- · 2020-02-29 04:04
add_action('woocommerce_created_customer', 'admin_email_on_registration', 10 , 1);
function admin_email_on_registration( $customer_id) {
    wp_new_user_notification( $customer_id );
}

woocommerce_created_customer is hook which is called when user created by woocommerce. It only sends notification to customer. we will use wp_new_user_notification() function to send notification to Admin.

查看更多
叼着烟拽天下
3楼-- · 2020-02-29 04:09

I'm assuming that you are using html inside emails. If you are using plain text the procedure is similar.

You need to override the woocommerce template structure. Here you can find how: http://docs.woothemes.com/document/template-structure/.

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 ); ?>

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');
查看更多
爷的心禁止访问
4楼-- · 2020-02-29 04:18

I was pulling my hair out trying to figure this same issue out and after going back and forth with the developers the default is to not send new customer registration notification emails to admin.

After trying various email plugins and even resorting to using WP SMTP Email, I finally decided to leave it alone.

That said, WooCommerce 2.0 was released today so it may be built in the new version.

查看更多
我只想做你的唯一
5楼-- · 2020-02-29 04:26

the answers is in the emails sections of "woocommerce / settings"

simply change the from email to wordpress@yourdomain.com

worked for me as i also had the same issues

查看更多
登录 后发表回答