• Resolved Beda

    (@bedas)


    Due to some issues with an external shipping management tool (Veeqo), I am debugging a website where the “Order Complete” email is never sent. Please see below the exact behaviour and debug done.

    1. If I trigger the “Order Complete” in the backend, manually, the email is sent
    2. If I add a hook as below shown to theme or plugin, to trigger the email when the order goes to complete, the email is never sent
    3. Similarly, if an external Tool like Veeqo sets the Order to complete, the email is never sent.

    Technically, if I add this to theme or plugin:

    
    function trigger_email_on_complete_status( $order_id, $old_status, $new_status ) {
    
    		// Check if the new status is 'completed'
    		if ( 'completed' == $new_status ) {
    			// Get the order object
    			$order = wc_get_order( $order_id );
    			// Ensure we have an order instance
    			if ( $order ) {
    				// Get the email instance related to completed orders
    				$mail = WC()->mailer()->emails['WC_Email_Customer_Completed_Order'];
    				$mail->trigger( $order_id );
    			}
    		}
    	}
    add_action( 'woocommerce_order_status_changed', 'trigger_email_on_complete_status', 10, 3 );
    

    … then the email should fire whenever the order goes to complete.
    And indeed, if I debug log the single Variables in that function I can see that:
    – the email is enabled
    – the recipient is set
    – the order status is correct (complete)
    – the mailer is instantiated

    …. yet, the email is NOT SENT by this code.
    I know this because:
    – when I trigger the “order complete” in the backend, and use above code, the email should be sent _twice_. But it is not, it is sent only _once_.
    – if any non-wp-admin related action (Veeqo, own custom code, etc) trigger the order complete, the email is not sent at all.

    Yet in all cases, the above function does get triggered, the mail data is instantiated, as I can see in the debug log… it just seems that send() of the WP_Mail class is never sending the mail.

    Note that ALL other emails (order received, etc) ARE sent just fine, in all cases, be it triggered manually or externally by Veeqo or via code.

    It is only this one email (WC_Email_Customer_Completed_Order) that is not sent.

    I am turning a bit in circles here, it is unclear why it does not work, and how to fix this.
    Of course, I already tried the basic things like testing with themes that are not modified, no plugins, and confirmed the issue happens in several different scenarios, no only when Veeqo is used.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi there @bedas 👋

    Thank you for contacting Woo support!

    Due to some issues with an external shipping management tool (Veeqo), I am debugging a website where the “Order Complete” email is never sent.

    From what I gather, you are interested in setting up an email automation with a trigger for when an order’s status changes to complete.

    My recommendation is to check out AutomateWoo, as it has a comprehensive list of triggers, which can be used to set up workflows like the one you are interested in.

    Keep in mind, if you want to try our products, you can leverage our 30-day refund policy. In a nutshell, it gives you 30 days to try it out, and if the product doesn’t work the way you need, or you think another product would work better, we are more than happy to offer a full refund. You’ll find the details of our refund policy here.

    I hope this is helpful! Please let us know if you have any further questions or concerns.

    Thread Starter Beda

    (@bedas)

    Hi, thanks for the answer.

    No, not really – I just would like the default email that WooCommerce has for when an order is complete, to work. Actually, I have this exact issue here (as many other users seem to have):
    https://wordpress.org/support/topic/order-complete-email-not-sending/

    However, in our case, it does not work even without any other plugins nr with StoreFront Theme

    I managed meanwhile to force-send an email using wp_mail() on the woocommerce_order_status_changed hook, so that part is resolved, yet, the default WooCommerce “Order Complete” Email, still does not send.

    This is true even if only WooCommerce, Veeqo Integration Plugin, and Storefront Theme are active.
    All other emails, work just fine.

    Plugin Support Kader Ibrahim S. a11n

    (@kaderibrahim)

    Hello @bedas,

    Thank you for getting back to us and for the additional context. I’ve tested the custom code you’ve shared initially and it works as expected. The trigger_email_on_complete_status does trigger the WC_Email_Customer_Completed_Order email. I received two emails on order completion.

    WooCommerce internally calls the wp_mail function to send emails. You can use the wp_mail_failed action to catch the reason for your email failure. Here is a sample code:

    add_action( 'wp_mail_failed', 'wc_log_failed_exception' );
    
    function wc_log_failed_exception( $error ) {
    	$logger = wc_get_logger();
    	$logger->log( 'debug', $error->get_error_message() );
    }

    The above sample code hooks into the wp_mail_failed action, which is fired on an email sent failure. You can use the WooCommerce logger to log the error and view the details.

    Alternatively, you can also use the woocommerce_email_sent action to see what went wrong. Here is another sample code:

    add_action( 'woocommerce_email_sent', 'wc_child_log_email', 10, 3 );
    
    function wc_child_log_email( $return, $id, $email_obj ) {
    	$logger = wc_get_logger();
    	if ( $return ) {
    		$message = $id . ' was sent';
    		$logger->log( 'debug', $message );
    	} else {
    		$message = $id . ' was not sent sent.';
    		$logger->log( 'debug', $message );
    	}
    }

    You can use the above sample code to check the details of the WC_Email_Customer_Completed_Order object.

    I hope this information is sufficient to debug the issue that you are facing. Please let us know if you need further help.

    steadylads

    (@steadylads)

    @kaderibrahim Thanks for these tips. I’m trying to determine if there are any conflicts with the official Shipment Tracking plugin. Will wp_mail_failed and woocommerce_email_sent help me diagnose if there is a conflict?

    anastas10s

    (@anastas10s)

    Hi there @steadylads 👋

    We’d like to take a look at your report on a separate thread, since this one is closed and technically resolved.

    Please open a new topic here: https://wordpress.org/support/plugin/woocommerce/#new-topic-0.

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WC “Order Complete” Email not sent’ is closed to new replies.