Guest User

Untitled

a guest
Dec 11th, 2017
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. add_filter( 'woocommerce_email_recipient_new_order', 'sv_conditional_email_recipient', 10, 2 );
  2.  
  3.  
  4. function sv_conditional_email_recipient( $recipient, $order ) {
  5.  
  6. // Bail on WC settings pages since the order object isn't yet set yet
  7. // Not sure why this is even a thing, but shikata ga nai
  8. $page = $_GET['page'] = isset( $_GET['page'] ) ? $_GET['page'] : '';
  9. if ( 'wc-settings' === $page ) {
  10. return $recipient;
  11. }
  12.  
  13. // just in case
  14. if ( ! $order instanceof WC_Order ) {
  15. return $recipient;
  16. }
  17.  
  18.  
  19. if ( in_array( 'wholesale_customer', (array) $user->roles ) ) {
  20. $recipient .= ', shaun@example.com';
  21. return $recipient;
  22. }
  23.  
  24. return $recipient;
  25. }
  26.  
  27.  
  28. add_filter( 'woocommerce_email_recipient_new_order', 'sv_conditional_email_recipient', 10, 2 );
  29.  
  30. add_filter( 'woocommerce_email_recipient_new_order', 'user_role_conditional_email_recipient', 10, 2 );
  31. add_filter( 'woocommerce_email_recipient_cancelled_order', 'user_role_conditional_email_recipient', 10, 2 );
  32. add_filter( 'woocommerce_email_recipient_failed_order', 'user_role_conditional_email_recipient', 10, 2 );
  33. function user_role_conditional_email_recipient( $recipient, $order ) {
  34.  
  35. Get the customer ID
  36. $user_id = $order->get_user_id();
  37.  
  38. // Get the user data
  39. $user_data = get_userdata( $customer_id );
  40.  
  41. // Adding an additional recipient for a custom user role
  42. if ( in_array( 'wholesale_customer', $user_data->roles ) )
  43. $recipient .= ', shaun@example.com';
  44.  
  45. return $recipient;
  46. }
Add Comment
Please, Sign In to add comment