Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a function to have more than one email address for a user account?

basically a customer who makes an order also gets sent a copy of the order to a different email address (cc/bcc)

share|improve this question
    
Please check this answer, [Adding a second email address to a completed order in WooCommerce][1] [1]: wordpress.stackexchange.com/questions/92020/… –  Rajeev Vyas Feb 13 at 7:33
    
@RajeevVyas looked at this before.. but its only a static email i want each user (customer) account to be able to have the option to have a CC/BCC email so when they make orders they can get a copy to another email. –  Daniel Morton Feb 13 at 10:57

1 Answer 1

up vote 1 down vote accepted

There is nothing out of the box that will let you send an email to multiple email address for one account, but you can hook a function to wp_mail filter and check based on to address or subject line and add your cc/bbc to that filter, ex:

// Add extra contact info fields to user profile page
function extra_contact_info_wpa_134454($contactmethods) {
    $contactmethods['bcc'] = 'Email BCC'; 
    $contactmethods['cc'] = 'Email CC'; 
    return $contactmethods;
}
add_filter('user_contactmethods', 'extra_contact_info_wpa_134454');

add_filter('wp_mail','add_cc_bcc_to_mail_wpa_134454');
function add_cc_bcc_to_mail_wpa_134454($args){
    //try to get the user id by the "to mail"
    $user = get_user_by( 'email', $args['to'] );
    if ($user){
        //get ccs if exists
        if ( ($cc = get_user_meta( $user->ID, 'cc', true ) ){
            //explode by comma "," to allow multiple cc addresses
            foreach ((array)explode(",", $cc) as $email) {
                $args['headers'][] = 'Cc: '.$email;
            }
        }

        if ( ($bcc = get_user_meta( $user->ID, 'bcc', true ) ){
            //explode by comma "," to allow multiple bcc addresses
            foreach ((array)explode(",", $bcc) as $email) {
                $args['headers'][] = 'Bcc: '.$email;
            }
        }
    }
    return $args;
}

Now on every mail send it will check if the mail belongs to a user and if it does it will check if that user has entered cc or bcc email addresses in his profile which will be added to that mail.

share|improve this answer
    
#bainternet, thanks the for reply back... am showing an error on both if ((%cc= get_user_.... lines any idea –  Daniel Morton Feb 13 at 9:53
    
ok took out one of the first ( and that seems to take the errors away! –  Daniel Morton Feb 13 at 10:14
    
But its not doing that i want!.. ok it adds extra fields to the user account... but if a customer places an order they dont get the email in there CC email address.. iv added to one customer acc. but that CC email is being used by the WP admin so its getting copies of admin emails and not the customer orders which is what i want..?? –  Daniel Morton Feb 13 at 10:21
    
the code i posted is an example only, you need\can tweak it to your needs. –  Bainternet Feb 13 at 14:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.