Untitled

 avatar
unknown
plain_text
25 days ago
1.2 kB
6
Indexable
/**
 * Send a copy of the "customer processing order" email to the vendor
 */
function send_processing_order_email_to_vendor($recipient, $order, $email_class) {
    // Make sure we have a valid order
    if (!is_a($order, 'WC_Order')) {
        return $recipient;
    }
    
    // Get the order ID
    $order_id = $order->get_id();
    
    // Get the vendor ID using the MarketKing function
    $vendor_id = marketking()->get_order_vendor($order_id);
    
    // If we have a valid vendor ID
    if ($vendor_id) {
        // Get the vendor's email address
        $vendor = get_user_by('id', $vendor_id);
        
        if ($vendor && isset($vendor->user_email)) {
            // Add the vendor's email to the recipient list
            // If there are already multiple recipients, they'll be comma-separated
            if (!empty($recipient)) {
                $recipient .= ',' . $vendor->user_email;
            } else {
                $recipient = $vendor->user_email;
            }
        }
    }
    
    return $recipient;
}
add_filter('woocommerce_email_recipient_customer_processing_order', 'send_processing_order_email_to_vendor', 10, 3);
Editor is loading...
Leave a Comment