【问题标题】:Woocommerce new customer administartion email notification with more fields具有更多字段的 Woocommerce 新客户管理电子邮件通知
【发布时间】:2017-04-08 22:31:24
【问题描述】:

我已尝试进一步开发@danielevigi 在Woocommerce New Customer Admin Notification Email 发布的代码,以便在新客户注册时创建一个管理员电子邮件。

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

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

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

【问题讨论】:

    标签: wordpress email woocommerce admin


    【解决方案1】:

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

    您可以使用

    检索用户 ID
    $user = get_user_by('login', $user_login);
    $user_id = $user->ID;
    

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

    希望有效果

    【讨论】:

    • 是的,它工作得很好!我仍然必须避免与对象混淆!确实感谢
    【解决方案2】:

    你不能在这个地方用get_user_meta从用户那里检索数据,因为用户的元数据还没有存储在数据库中,你可以从$_POST的post请求中获取数据,例如:

    $_POST['billing_first_name'];

    也许您可以在woocommerce_created_customer 钩子check this answer 中挂钩电子邮件的发送。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-24
      • 2017-05-19
      • 1970-01-01
      • 2021-11-05
      • 2018-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多