Php WooCommerce向管理员发送电子邮件通知特定订单状态
以下是我在订单状态变为“正在处理”时向管理员发送通知电子邮件的代码:Php WooCommerce向管理员发送电子邮件通知特定订单状态,php,wordpress,woocommerce,orders,email-notifications,Php,Wordpress,Woocommerce,Orders,Email Notifications,以下是我在订单状态变为“正在处理”时向管理员发送通知电子邮件的代码: add_action( 'woocommerce_checkout_order_processed', 'process_new_order_notification', 20, 1 ); function process_new_order_notification( $order_id ) { // Get an instance of the WC_Order object $order = wc_g
add_action( 'woocommerce_checkout_order_processed', 'process_new_order_notification', 20, 1 );
function process_new_order_notification( $order_id ) {
// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );
//Order status processing
if( ! $order->has_status( 'processing' ) ) return;
// Send "New Email" notification (to admin)
WC()->mailer()->get_emails()['WC_Email_New_Order']->trigger( $order_id );
}
但这不起作用,因为当订单状态变为“正在处理”时,管理员不会收到任何电子邮件。我想我的代码有问题。有任何帮助吗?您可以使用woocommerce\u order\u status\u TRANSITION[to]复合钩子处理status TRANSITION将$status\u TRANSITION[to]更改为processing,这将简化和压缩代码,如:
add_action( 'woocommerce_order_status_processing', 'process_new_order_notification', 20, 2 );
function process_new_order_notification( $order_id, $order ) {
// Send "New Email" notification (to admin)
WC()->mailer()->get_emails()['WC_Email_New_Order']->trigger( $order_id );
}
代码进入活动子主题或活动主题的function.php文件。它应该更有效
自5+以来:
您可以使用woocommerce\u order\u status\u TRANSITION[to]复合钩子处理status TRANSITION将$status\u TRANSITION[to]更改为processing,这将简化和压缩代码,如:
add_action( 'woocommerce_order_status_processing', 'process_new_order_notification', 20, 2 );
function process_new_order_notification( $order_id, $order ) {
// Send "New Email" notification (to admin)
WC()->mailer()->get_emails()['WC_Email_New_Order']->trigger( $order_id );
}
代码进入活动子主题或活动主题的function.php文件。它应该更有效
自5+以来: