0
votes

I have added a custom shipping option which works great, however duplicate emails are sent - my custom shipping new order email and the standard admin new order email.

In WooCommerce > Settings > Email I have added a new option for my custom shipping and added recipients and so on. What I think I need to do now is put a condition in to the Admin New Order section, something along the lines of..

if(shipping method == 'Custom Shipping')
      return; // this can just bail out as a custom shipping email is being sent

I think this will stop the standard new order email being sent if the order uses Custom Shipping.

Can anyone give me guidance on how I can implement this? Do I put code in to the admin-new-order.php file with this if statement? Thank you

1

1 Answers

1
votes

You could remove the standard mail actions: https://docs.woocommerce.com/document/unhookremove-woocommerce-emails/

And then intercept the order_status_changed hook to trigger your mail depending on conditions (like the shipping method): https://docs.woocommerce.com/wc-apidocs/class-WC_Order.html

function your_function($id)
{

    $order = wc_get_order($id);

    if (!empty($order) && $order->get_shipping_method() === 'Custom Shipping') {
        do_action('woocommerce_before_resend_order_emails', $order, 'email_name');
        // prepare your email
        do_action('woocommerce_after_resend_order_email', $order, 'email_name');
    }
}
add_action('woocommerce_order_status_changed', 'your_function');