Home > Net >  Sending order notifications to the user to the billing email address and to the client profile email
Sending order notifications to the user to the billing email address and to the client profile email

Time:01-28

Sending order notifications to the user to the billing email address and to the client profile email address.

When I create an order in the backend Woocommerce, I select an existing user on the site, this user has different emails in the profile and in the billing.

By default, order details are sent only to the billing address, but I need to duplicate them to the customer profile address as well.

How can I do that in Woocommerce?

CodePudding user response:

You can use a plugin like "WooCommerce Custom Order Status Email" or "WooCommerce Order Status Control" to add a custom email notification that is sent to the customer profile email address when a specific order status is updated. You can also use the WooCommerce action hooks to programmatically add a second email recipient for order notifications.

You can add this code to your functions.php file:

add_filter( 'woocommerce_email_recipient_new_order', 'add_email_recipient', 10, 2 );
function add_email_recipient( $recipient, $order ) {
    $user_id = $order->get_user_id();
    $user = get_userdata( $user_id );
    $recipient .= ',' . $user->user_email;
    return $recipient;
}

This will add the customer profile email address as a second recipient for new order notifications.

CodePudding user response:

You can add this to your functions.php file in your theme:

function custom_woocommerce_email_recipient( $recipient, $object, $email ) {
    // Only target "new order" email notifications
    if ( $email->id === 'new_order' ) {
        // Get the user's billing email address
        $billing_email = $object->get_billing_email();
        // Get the user's customer profile email address
        $profile_email = $object->get_user()->user_email;
        // Add the customer profile email address to the recipient list
        $recipient .= ',' . $profile_email;
    }
    return $recipient;
}
add_filter( 'woocommerce_email_recipient', 'custom_woocommerce_email_recipient', 10, 3 );
  • Related