Hi again, Marcel!
Sorry for the long delay, but I couldn’t get back into this until today.
After quite a lot of testing, I believe there are actually two bugs / issues. I’ll explain them following the order in which I think they’ll be easier to understand / solve.
First issue
On a clean WordPress instance, I installed:
- EDD
- Email Users on Update of Download for Easy Digital Downloads
I activated both, and added some Downloads and “bought” them through the Store Gateway using one of my users.
After doing so, when clicking on the Send Email to Customers, in order to notify them of a change, nothing happens (i.e. no email is sent, and there is no message either).
<span style=”text-decoration: underline;”>How to solve this</span>
In the file edd-email-user-admin-ajax.php, I changed the following condition in function edd_email_on_update_get_recipients($download_id):
if (false === $recipients){
to:
if ( (false === $recipients) || (count($recipients) === 0 ) ) {
Bear in mind that this bug only happens the first time you try to send an email to the customers of a certain Download. If an email is sent successfully for a certain Download, and then the code is reverted back to the original if condition, on the following attempts everything works correctly.
I had already included this change when I first got in touch, but didn’t realise that this first-email issue was there.
BTW, I tested this on a local WordPress install, using Local by Flywheel.
Second issue
I believe this second issue might be due to what you mentioned:
It could be that another plugin that has a metabox on the edit page has a bug, where it overwrites the post ID. That way the download_id in this plugin will have the wrong value. Since the metabox of this plugin is loaded quite late in the list of metaboxes, there is a bit of chance for that to happen.
I deactivated all plugins on a replica of my client’s website, and activated them in blocks, and I believe I found the culprit: Easy Media Gallery. When it’s active, no emails are sent because of the wrong ids. This happens under the following conditions:
- Only active plugins are EDD + Email Users on Update… + Easy Media Gallery
If I activate all plugins, except Easy Media Gallery, it works and emails are sent.
However, when I tried to reproduce the issue on a clean install, with the bare minimum:
- EDD
- Email Users on Update of Download for Easy Digital Downloads
- Easy Media Gallery
Everything works properly.
I’m quite baffled as to what is going on. Any idea of what could be wrong, and why the difference in behaviour? I’d like to figure it out, but at the same time, I’m not sure it’s worth it considering that it seems difficult to find the exact conditions under which it can be reproduced.
BTW, the code I sent you a few months back seems to solve the issue.
I think you want to use the permalink here to obtain the post ID?
That would mean that the download_id was not set correctly or not available in the callback function.
Yes, the id was wrong and I was trying to get the good one from the permalink.
Thanks again for your time.
Kind regards,
Montse