Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'woocommerce_email_recipient_new_order', 'sv_conditional_email_recipient', 10, 2 );
- function sv_conditional_email_recipient( $recipient, $order ) {
- // Bail on WC settings pages since the order object isn't yet set yet
- // Not sure why this is even a thing, but shikata ga nai
- $page = $_GET['page'] = isset( $_GET['page'] ) ? $_GET['page'] : '';
- if ( 'wc-settings' === $page ) {
- return $recipient;
- }
- // just in case
- if ( ! $order instanceof WC_Order ) {
- return $recipient;
- }
- if ( in_array( 'wholesale_customer', (array) $user->roles ) ) {
- $recipient .= ', shaun@example.com';
- return $recipient;
- }
- return $recipient;
- }
- add_filter( 'woocommerce_email_recipient_new_order', 'sv_conditional_email_recipient', 10, 2 );
- add_filter( 'woocommerce_email_recipient_new_order', 'user_role_conditional_email_recipient', 10, 2 );
- add_filter( 'woocommerce_email_recipient_cancelled_order', 'user_role_conditional_email_recipient', 10, 2 );
- add_filter( 'woocommerce_email_recipient_failed_order', 'user_role_conditional_email_recipient', 10, 2 );
- function user_role_conditional_email_recipient( $recipient, $order ) {
- Get the customer ID
- $user_id = $order->get_user_id();
- // Get the user data
- $user_data = get_userdata( $customer_id );
- // Adding an additional recipient for a custom user role
- if ( in_array( 'wholesale_customer', $user_data->roles ) )
- $recipient .= ', shaun@example.com';
- return $recipient;
- }
Add Comment
Please, Sign In to add comment