允许在 WooCommerce 5+ 中重新发送新订单通知

Allow re-sending New Order Notification in WooCommerce 5+

我一直在使用以下代码段,没有任何问题。无缘无故我能想到它今天停止触发了。

能不能写得更好一些?

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 );
}

自 WooCommerce 5.0 a new filter hook has been added 起,禁用重新发送“新订单”电子邮件通知,限制此特定通知仅发送一次。

这是添加到 WC_Email_New_Order trigger() 方法中的内容 (默认设置为 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;
}

所以您现在需要添加这段额外的代码来解锁此通知:

add_filter('woocommerce_new_order_email_allows_resend', '__return_true' );

代码进入活动子主题(或活动主题)的 functions.php 文件。已测试并有效。

现在您的代码又可以工作了。

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.