Woocommerce具有更多字段的新客户管理电子邮件通知 [英] Woocommerce new customer administartion email notification with more fields

查看:85
本文介绍了Woocommerce具有更多字段的新客户管理电子邮件通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图进一步开发@danielevigi在 Woocommerce新客户管理员中发布的代码通知电子邮件,用于在新客户注册时创建管理员电子邮件。

I have tried to further develop the code posted by @danielevigi at Woocommerce New Customer Admin Notification Email to create an admin email when new customer register.

我不仅要向电子邮件中添加$ user_login,还要向注册表单中添加如下字段:

I wanted to add to the email not only the $user_login, but the fields that are present in the registration form as follows:

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

    $billing_first_name = '';
    $billing_last_name = '';
    $billing_phone = '';
    $w55 = '';

    $user_id = get_user_by('login', $user_login);
    if ($user_id)
    {
    $billing_first_name = get_user_meta($user_id, 'billing_first_name', true);
    $billing_last_name = get_user_meta($user_id, 'billing_last_name', true);
    $billing_phone = get_user_meta($user_id, 'billing_phone', true);
    $w55_card = get_user_meta($user_id, 'w55', true);
      if($w55_card === 'y')
      {
          $tessera = 'Voglio iscrivermi a Wision55';
      }
      else
      {
          $tessera = '';
      }
    }

  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>' .
    '<p>Nome: <span style="font-size:16px; font-weight: bold;">' .$billing_first_name .'<span></p>
     <p>Cognome: <span style="font-size:16px; font-weight: bold;">' .$billing_last_name .'<span></p>
     <p>Telehone: <span style="font-size:16px; font-weight: bold;">' .$billing_phone .'<span></p>
     <p>Tessera W55: <span style="font-size:16px; font-weight: bold;">' .$tessera .'<span></p>'
    .$email_footer
  );
}
add_action('new_customer_registered', 'new_customer_registered_send_email_admin');

不过,电子邮件是在字段为空的情况下发送的。我想知道我做错了什么...有人可以帮助我吗?

However the email is sent with the fields empty. I wonder what am I doing wrong... Anybody could help me?

推荐答案

使用 get_user_by 时,成功返回WP_User对象。

When using get_user_by, the return is the WP_User object on success.

您可以通过以下方式检索用户ID:

You can retrieve the user ID with

$user = get_user_by('login', $user_login);
$user_id = $user->ID;

您可以阅读有关此功能的更多信息此处

You can read more about this function here

希望它能正常工作

这篇关于Woocommerce具有更多字段的新客户管理电子邮件通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆