Allow re-sending New Order Notification in WooCommerce 5+
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 );
}
Solution 1:
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.