0

We have three different customer groups with different customer managers for each group. Is there a way to send Woocommerce order confirmation emails to cusomer managers based on the group? For example:

  • we have user role "Gold" for group 1. Customer manager has email gold@mysite.com
  • another group is "Silver". Customer manager has email
    silver@mysite.com

Now if customer from group 1 (Gold) makes an order then order notification email should be sent to gold@mystite.com. If customer from group Silver makes an oder then order notification should be sent to email silver@mysite.com

Currently we have tried this code snippet here, but it also sends email to admin. We would like to send email to admin if customer is none of the user roles described above.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
soldier99
  • 123
  • 4
  • 9

2 Answers2

1

Try this below code .

add_action( 'init', 'Change_admin_mail_email');

function Change_admin_mail_email(){  


  global $wp_roles;

  $roles = $wp_roles->get_names();
  $roles =array_keys($roles);


         foreach($roles as $User_role_value)

         {
            add_filter( 'woocommerce_email_from_address', function( $from_email, $wc_email ){

                if($User_role_value=='gold')
                {
                      $from_email = 'gold@mysite.com';
                }
                elseif($User_role_value=='silver')


                {
                     $from_email = 'silver@mysite.com';
                }


                elseif($User_role_value=='platinum')
                {
                     $from_email = 'platinum@mysite.com';
                }


            return $from_email;
            }, 10, 2 );  

         }

}
Kanewilliam
  • 199
  • 2
  • 18
  • Unfortunately these snippets are not working in a way i wanted it. These snippets changed "from email" address but what is described is that order email admin notification should be sent to diffetrent admin emails based on the user roles. – soldier99 Jul 31 '18 at 11:10
0

Try this below code your current active theme functions.php file.

add_filter( 'woocommerce_email_from_address', function( $from_email, $wc_email ){

    $user_id = get_current_user_id();
    $user_data = get_userdata( $user_id );

    if ( in_array( 'gold', $user_data->roles )  )
    {
        $from_email = 'gold@mysite.com';
    }

    elseif ( in_array( 'silver', $user_data->roles )  )
    {
            $from_email = 'silver@mysite.com';
    }

    elseif ( in_array( 'platinum', $user_data->roles )  )
    {
            $from_email = 'platinum@mysite.com';
    }

    return $from_email;
}, 10, 2 );  
VinothRaja
  • 1,405
  • 10
  • 21
  • Unfortunately these snippets are not working in a way i wanted it. These snippets changed "from email" address but what is described is that order email admin notification should be sent to diffetrent admin emails based on the user roles. – soldier99 Jul 31 '18 at 18:52