4

I've been using the following snippet without any issues. For no reason that I can think of it stopped being triggered today.

Could it perhaps be written better?

add_action('woocommerce_order_status_completed', 'email_completed_order_admin_notification', 10, 2 );
function email_completed_order_admin_notification( $order_id, $order ) {
    WC()->mailer()->get_emails()['WC_Email_New_Order']->trigger( $order_id );
}

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • Maybe I haven't been paying attention. I'll create the thread on the WooCommerce plugin support page. Thanks for the heads up! – Wanderlust Consulting Mar 12 '21 at 17:23
  • 1
    Found the way and works now back again. – LoicTheAztec Mar 12 '21 at 17:32
  • 1
    I have opened an issue, as main hook argument should be set to true by default (as mentioned on the comment bloc), should allow by default to resend New Order Notification: https://github.com/woocommerce/woocommerce/issues/29367 – LoicTheAztec Mar 12 '21 at 17:52

1 Answers1

4

Since WooCommerce 5.0 a new filter hook has been added, that disables resending "New Order" email notification, restricting this specific notification to be sent only one time.

This is what has been added to WC_Email_New_Order trigger() method (default is set to false):

/**
 * Controls if new order emails can be resend multiple times.
 *
 * @since 5.0.0
 * @param bool $allows Defaults to true.
 */
if ( 'true' === $email_already_sent && ! apply_filters( 'woocommerce_new_order_email_allows_resend', false ) ) {
    return;
}

So you need now to add this little additional piece of code, to unlock this notification:

add_filter('woocommerce_new_order_email_allows_resend', '__return_true' );

Code goes in functions.php file of the active child theme (or active theme). Tested and works.

Now your code will work again.

I have opened an issue on WooCommerce Github, as main hook argument should be set to true by default (as mentioned on the comment bloc), and should allow by default to resend New Order Notification.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • The aforementioned issue was closed without behaviour changes. WooCommerce staff confirmed that sending notification email to customer just once is the intended behaviour. – cardy Aug 13 '21 at 07:52