【问题标题】:Disable WooCommerce email notification for specific customer group or user role禁用特定客户组或用户角色的 WooCommerce 电子邮件通知
【发布时间】:2019-03-12 21:55:57
【问题描述】:

我正在寻找一种解决方案,当来自特定客户组(用户角色)的客户完成订单时,我们可以禁用 woocommerce 发送电子邮件通知。

我找到了有关阻止为特定产品 ID 发送电子邮件的情况的答案。 Disable WooCommerce email notification for specific product。 也许这对于我们的“问题”也是可能的?

亲切的问候, 基斯

【问题讨论】:

  • 嘿@Kees,梅尔文的建议行得通吗?过去一年有什么问题吗?
  • @Liv 当我发布答案时代码正在运行。希望是现在

标签: wordpress email woocommerce notifications


【解决方案1】:

您可以将钩子用于任何电子邮件,并且在回调函数中您可以检查用户是否具有特定角色

function change_new_order_email_recipient( $recipient, $order ) {
  global $woocommerce;
  $uid = $order->get_user_id();
  $user_meta=get_userdata($uid);
  $user_roles=$user_meta->roles;
  if(in_array('customer', $user_roles)){ // Prevent email if user role is customer
    $recipient ='';
  }
  return $recipient;
}
add_filter('woocommerce_email_recipient_customer_completed_order', 'change_new_order_email_recipient', 1, 2);

我已经快速检查了代码并且正在运行

【讨论】:

  • 嗨@Melvin,可以反过来做吗?只向特定角色发送电子邮件而不向任何其他角色发送电子邮件?
  • 您是说如果用户具有特定的用户角色,您需要发送客户完成的电子邮件吗?如果是的话,这是可能的。如果不是,你能说清楚吗?
  • 我不想将第一封“收到订单”和第二封“订单已处理”电子邮件发送给除“客户”角色之外的任何角色。原因是我使用批发角色,他们不应该收到这些电子邮件。这可能吗?
  • @Liv 我认为上面的相同功能可以挂接到woocommerce_email_recipient_customer_on_hold_orderwoocommerce_email_recipient_customer_processing_order 以实现您的目标。还可以根据需要更改 if 条件中的 in_array。我没有测试过这个。但我希望它会工作
  • 我找到了另一种策略来解决我的问题,以及有助于我们的会计软件下游的一些东西。我想要的是仅将 woocommerce 电子邮件发送到用户帐户电子邮件地址而不是计费电子邮件地址。这在此处讨论stackoverflow.com/questions/54628979/…。但是那里没有回应,您有什么想法吗?
猜你喜欢
  • 2018-08-31
  • 1970-01-01
  • 2019-08-24
  • 2022-11-10
  • 2018-07-04
  • 1970-01-01
  • 2022-10-05
  • 1970-01-01
  • 2018-06-22
相关资源
最近更新 更多