问题描述
我一直在使用以下代码段,没有任何问题。无缘无故,我能想到它今天停止被触发。
能不能写得更好?
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 文件中。经测试有效。
现在您的代码将再次运行。
我有 opened an issue on WooCommerce Github,因为主钩子参数默认应设置为 true
(如评论块中所述),并且默认情况下应允许重新发送新订单通知。