I’m using your plugin to send tracking number with email to customers, It’s ok but I need to send a copy of the same email to a sales manager responsible. I’ve done the same thing for the WooCommerce order confirmation email. Here’s the script I’ve created. I want to do the same when sending the tracking email to the customer. It should also be sent to the sales manager.
Example:
//START send each customer email also to the agent
function send_email_to_agent( $recipient, $order ) {
// Bail on WC settings pages since the order object isn't yet set yet
$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 the customer of this order, or his group has an assigned agent
$customer_id = $order->get_customer_id();
// first, check if the customer has an agent assigned directly.
$customer_agent = get_user_meta($customer_id,'salesking_assigned_agent', true);
if (!empty($customer_agent) && $customer_agent !== 'none'){
// found agent
} else {
// keep searching in the group
$customer_is_b2b = get_user_meta($customer_id,'b2bking_b2buser', true);
if ($customer_is_b2b === 'yes'){
$customergroup = get_user_meta($customer_id, 'b2bking_customergroup', true);
$customer_agent = get_post_meta($customergroup, 'salesking_assigned_agent', true);
}
}
if (empty($customer_agent) or $customer_agent === 'none'){
$order_id = $order->get_id();
$customer_agent = $order->get_meta('salesking_assigned_agent');
}
if (!empty($customer_agent) && $customer_agent !== 'none'){
// send email to agent as well
$agent_info = get_userdata($customer_agent);
$agent_email = $agent_info->user_email;
$recipient .= ', '.$agent_email;
}
return $recipient;
}
add_filter( ‘woocommerce_email_recipient_customer_completed_order’, ‘send_email_to_agent’, 10, 2 );
I need to do something similar with the tracking number