【问题标题】:Send Woocommerce new order email notification from specific user role to specific user从特定用户角色向特定用户发送 Woocommerce 新订单电子邮件通知
【发布时间】:2018-08-31 02:19:29
【问题描述】:

我们有一个“主要批发商”负责其他批发商。与其他批发商一样,该批发商被分配给用户角色:wholesale_customer
“主要批发商”为其店铺下单,其他批发商照常为自己的店铺下单。

我希望“主要批发商”在其他批发商下订单时收到电子邮件通知,这样当其他批发商下订单时他会收到通知,因为他会获得佣金。

那么有没有办法让“主要批发商”在其他批发商下订单时收到电子邮件通知?

也许这可以通过类似这样的函数来完成: WooCommerce email notifications: different email recipient for different cities

感谢任何帮助。

【问题讨论】:

    标签: php wordpress woocommerce user-roles email-notifications


    【解决方案1】:

    更新 (解决了后端电子邮件设置中的错误)

    当其他wholesale_customer用户角色将进行购买时,以下功能将向“批发经理”发送额外的“新订单”电子邮件通知。

    您只需在此函数中设置“批发经理”的用户 ID……

    add_filter( 'woocommerce_email_recipient_new_order', 'wholesale_manager_email_recipient', 20, 2 );
    function wholesale_manager_email_recipient( $recipient, $order ) {
        if( is_admin() ) return $recipient;
    
        // Only for 'wholesale_customer' user role
        if( is_admin() || ! user_can( $order->get_user_id(), 'wholesale_customer' ) )
            return $recipient; // Exit if not a 'wholesale_customer'
    
        // HERE Set the main wholesale manager user ID
        $manager_id    = 5;
    
        $manager_user  = new WP_User( $manager_id );
        $manager_email = $manager_user->user_email;
    
        // Add manager email when other 'wholesale_customer' place orders
        if ( $order->get_user_id() != $manager_id )
            $recipient .= ',' . $manager_email; // coma separate emails
    
        return $recipient;
    }
    

    代码进入您的活动子主题(或主题)的 function.php 文件中。经过测试并且可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-12
      • 2019-07-22
      • 1970-01-01
      • 2017-08-08
      • 2018-07-04
      • 2020-10-02
      • 1970-01-01
      • 2019-05-10
      相关资源
      最近更新 更多