Search code examples
phpwordpresswoocommercepayment-gatewayemail-notifications

Send New Order email to an additional email based on payment type in Woocommerce


Let me start by saying that I have no code yet, and have researched this without finding anything. If anyone could point me in the right direction, it would be great.

Basically, I want to preferably use a code functions.php that checks the payment method of a WooCommerce order and sends the standard new order email to a specific email address. This address could be hardcoded to make it more simple.

What I want to achieve is that every time an order is placed with Stripe as the payment method, the standard new order email is sent to this additional email address while also being sent to the specified address in the WoocCommerce settings. If any other payment method is used, nothing should happen besides the normal new order email getting sent.

I would be very thankful if anyone could point me in the right direction, but please keep in mind that I am not a super-coder by any means.


Solution

  • Try the following code that will add an additional recipient to "New Order" email for stripe payment gateway:

    add_filter( 'woocommerce_email_recipient_new_order', 'new_order_additional_recipients', 20, 2 );
    function new_order_additional_recipients( $recipient, $order ) {
        if ( ! is_a( $order, 'WC_Order' ) ) 
            return $recipient;
    
        // Set Below your additional email adresses in the arrayy
        $emails = array('name1@domain.com');
        $emails = implode(',', $emails);
    
        // Adding recipients conditionally
        if ( 'stripe' == $order->get_payment_method() )
            $recipient .= ',' . $emails;
    
        return $recipient;
    }
    

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