• Resolved mpweblab

    (@mpweblab)


    Hello,

    I identified a duplicate email issue related to the plugin when editing an order or changing its status to “completed” from the WooCommerce admin.

    Environment:

    • Latest version of WooCommerce
    • Latest version of WooCommerce PDF Invoices & Packing Slips
    • WP Mail SMTP enabled
    • Issue reproduced both locally (MailHog) and in production (Brevo SMTP)

    To diagnose the issue accurately, I developed a custom WordPress email debugging plugin that traces wp_mail() calls with full stack traces, hooks, and plugin origin detection.

    Issue:
    When the order status changes to “completed”, WooCommerce correctly sends the “completed order” email once.

    Then, the plugin triggers a second identical email.

    The second send appears to originate from:

    File:
    wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/Admin.php

    Line:
    1563

    Method:
    send_emails()

    Detected trace:

    #4
    wp_mail
    woocommerce/includes/emails/class-wc-email.php : 1136

    #5
    send
    woocommerce/includes/emails/class-wc-email-customer-completed-order.php : 79

    #6
    trigger
    WC_Email_Customer_Completed_Order

    #7
    send_emails
    woocommerce-pdf-invoices-packing-slips/includes/Admin.php : 1563

    The plugin appears to call:
    WC_Email_Customer_Completed_Order->trigger()

    even though WooCommerce has already sent this email earlier in the same request.

    Result:
    Customers receive the same “completed order” email twice.

    The issue is consistently reproducible when:

    • editing an order from wp-admin
    • changing the order status to “completed”

    Additional information:

    • disabling the plugin immediately removes the duplicate email issue
    • the problem occurs even without Brevo (reproduced locally with MailHog)
    • WP Mail SMTP is probably not responsible, as it only handles email transport

    You may want to check whether send_emails() should ignore WooCommerce transactional emails that were already sent during the same workflow, or prevent a second trigger of WC_Email_Customer_Completed_Order.

    Thanks.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor Darren Peyou

    (@dpeyou)

    Hey @mpweblab,

    – When you performed a test with Brevo deactivated and the issue persisted, what were you using for handling emails?
    – Are you able to perform a test with WP Mail SMTP and Brevo SMTP deactivated?

    Thread Starter mpweblab

    (@mpweblab)

    Thanks for your reply.

    To clarify my testing setup and results:

    I performed tests locally using Local Sites on Linux with MailHog for email interception.

    During those tests, Brevo was completely disabled.

    WP Mail SMTP was configured to route emails to MailHog. If I disable WP Mail SMTP in this environment, emails are no longer captured, so that specific test is not meaningful in my local setup.

    To investigate further, I created my own wp_mail logger plugin.

    The result is:

    • only ONE wp_mail() call is logged for the “Customer Completed Order” email;
    • source: WooCommerce (class-wc-email.php);
    • the PDF attachment is already present in that single wp_mail() call.

    However, MailHog receives two identical emails.

    Additionally, I can reproduce the exact same behavior in production:

    • WP Mail SMTP enabled,
    • Brevo SMTP enabled,
    • real mailbox recipient,
    • duplicate emails still received.

    So the issue does not appear to be limited to MailHog or the local environment.

    Based on the wp_mail logs, I currently only see one email generation event, but two deliveries.

    Does PDF Invoices perform any additional processing after wp_mail() is called, or have you seen cases where PDF attachment handling could lead to duplicate delivery?

    I can provide logs if needed.

    Thread Starter mpweblab

    (@mpweblab)

    One additional observation that may help isolate the issue:

    The duplicate email never happens when I complete an order directly from the orders list screen.

    I can reproduce it only with this exact workflow:

    1. Open a specific order,
    2. Change the status to Completed,
    3. Use the PDF Invoices metabox action to save and send the email.

    I never click the WooCommerce “Update” button during this process.

    So the duplication appears to happen only from the order edit screen workflow combined with the PDF Invoices email action.

    Plugin Contributor Darren Peyou

    (@dpeyou)

    Hey @mpweblab,

    Your last message was very useful.

    • Changing the order status to “Completed” will already trigger a woocommerce order notification email. In your case, I believe that is the only action that needs to be performed.
    • The “Send order email” postbox is for manually re-sending the woocommerce order notification email. It will also save the order, so that must be why you receive 2 emails. This feature is useful for when a user claims to not have received a certain email or for testing purposes.

    Thread Starter mpweblab

    (@mpweblab)

    Thanks for the clarification.

    I performed another test following your recommended workflow.

    When I use only “Save order & send email” from the PDF Invoices metabox:

    • the email is sent,
    • but the order remains in Pending status.

    To actually finalize the order for accounting purposes, I still need to change the order status to Completed afterwards.

    However, when I change the order to Completed, WooCommerce sends the same customer email again.

    So in practice, for this workflow, I always end up with:

    1. one email sent via the PDF Invoices metabox,
    2. one identical WooCommerce completed order email.

    Since my orders need to end in Completed status, I currently do not see a way to avoid sending two identical emails when working from the single order page.

    Interestingly, when I complete orders directly from the orders list screen, this issue does not occur: only one email is sent and the invoice is attached correctly.

    So I wanted to ask: is there an intended workflow or built-in function for this use case (sending the invoice while ending with a Completed order status without sending duplicate customer emails)?

    Plugin Contributor Darren Peyou

    (@dpeyou)

    @mpweblab,

    You only need to change the order status to “Completed“, click “Update“, then the email will only get sent once.

    Based on your description, I do not see a reason why you would send the order email manually. Maybe there is some info you are forgetting to share?

    Thread Starter mpweblab

    (@mpweblab)

    Thank you, I think I understand the current behavior now.

    After further testing, I can confirm that the PDF invoice is correctly attached when the order status is changed to “Completed”.

    My concern is therefore no longer really about duplicate emails, but rather about the workflow when working from the order edit page.

    When I complete an order from the orders list screen, the customer receives a single email with the PDF invoice attached, which is exactly the behavior I am looking for.

    However, when working from a specific order page, I end up sending:

    • the WooCommerce “Completed Order” email (with the PDF invoice attached),
    • and then an additional “Order Details” email.

    Technically these are two different emails, but from the customer’s perspective, this can feel like unnecessary email clutter.

    In my business, I mainly work from the individual order page rather than from the orders list screen. That is why I am trying to achieve the same “single email with PDF invoice attached” workflow directly from that interface.

    Is there a recommended workflow for merchants who primarily manage orders from the individual order page and want to ensure that only one customer email is sent when the order is marked as “Completed”?

    Plugin Contributor Darren Peyou

    (@dpeyou)

    @mpweblab,

    My understanding is that the “Order Details” email is purely a manual email, it does not get sent automatically. You can simply decide not to send it. 🙂

    The workflow I recommend for you is still the same. Just avoid sending manual emails unless you absolutely need to. Simply rely on the email that is sent when the status is changed to “Completed” and “Update” is clicked. You are already attaching pdfs to that email via our plugin’s settings.

    It seems this is now turning into a WooCommerce question. I am going to mark this issue as resolved, as the initial statement has been addressed.

    Thread Starter mpweblab

    (@mpweblab)

    Thank you very much for your help and for taking the time to investigate this with me.

    I now understand the intended workflow and can confirm that everything is working as expected on my side.

    Thank you as well for your patience and kindness throughout this discussion. I appreciate the detailed explanations and your assistance in helping me better understand the interaction between WooCommerce and PDF Invoices.

    Have a great day.

Viewing 9 replies - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.