skip to Main Content

I have a custom field that contains an additional customer email account.

My idea is that when an order changes state WAIT, PENDING, PROCESSING or COMPLETED, it will reach the email of the one configured in this field.

Is this possible?

There is no problem that requires programming, but I don’t know what hook to use.

Thank you.

3

Answers


  1. This might be quite useful:
    https://www.skyverge.com/blog/add-woocommerce-email-recipients-conditionally/
    I would take a look at the Considerations section.

    Login or Signup to reply.
  2. You could use woocommerce_order_status_changed hook for example to notify someone each time an order change of status, like in this example:

    add_action('woocommerce_order_status_changed', 'send_custom_email_notifications', 10, 4 );
    function send_custom_email_notifications( $order_id, $old_status, $new_status, $order ){          
    
        $to_email    = '[email protected]'; // <= Replace with your email custom field (the recipient)
        $shop_name   = __('Shop name'); // Set the shop name
        $admin_email = '[email protected]'; // Set default admin email
    
        $subject  = sprintf( __('Order %s has changed to "%s" status'), $order_id, $new_status ); // The subject
        $message  = sprintf( __('Order %s has changed to "%s" status'), $order_id, $new_status ); // Message content
        $headers  = sprintf( __('From: %s <%s>'), $shop_name, $admin_email ) . "rn"; // From admin email
    
        wp_mail( $to_email, $subject, $message, $headers ); // Send the email
    }
    

    Code goes in functions.php file of your active child theme (or active theme). Tested and works

    Login or Signup to reply.
  3. Add the follows code snippet in your active theme’s functions.php –

    function add_cc_to_wc_order_emails( $header, $mail_id, $mail_obj ) {
        $available_for = array( 'customer_on_hold_order', 'customer_processing_order', 'customer_completed_order' );
        if( in_array( $mail_id, $available_for ) ) {
            $cc_email = '[email protected]';
            $cc_username = "yourCCUser";
            $formatted_email = utf8_decode( $cc_username . ' <' . $cc_email . '>' );
            $header .= 'Cc: ' . $formatted_email . "rn";
        }
        return $header;
    }
    add_filter( 'woocommerce_email_headers', 'add_cc_to_wc_order_emails', 99, 3 );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search