Skip to content
Advertisement

Sending WooCommerce new order email notification to related managers

So, the website is set up something like this:
There are 2 types of roles, 1 who place orders (client), 1 who process orders (manager).
These can be divided into groups, each with their own clients and managers (multiple of each possible).
The managers need to get a notification of new orders within their group and to cover for holidays and sick days, every manager gets every order within their group.
I’ve gotten to the point where the managers get the new order email, however, they get the mail multiple times. The amount of duplicate mails sent is the same as the amount of emails added to the recipient list and I can’t, for the life of me, figure out why.

Code:

JavaScript

Everything I find is the exact same as what I have. Comma separated list of addresses should work. There’s no payment system, so no external triggers. Tested by adding and removing managers from a group and the amount of duplicates changes with that.

Help would be appreciated as it’s stumped me for days now.

Advertisement

Answer

First you can’t get the current user ID on email notifications, as it’s a background process. What you can get is the customer ID that belongs to the order using the WC_Order method get_customer_id().

Now you get duplicated emails because there are some mistakes in your code, that can be simplified.

I suppose that “manager” is a custom user role as WooCommerce uses “shop_manager”

So try the following instead:

JavaScript

Code goes in functions.php file of your active child theme (or active theme). It should works (untested).

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement