以下是我在訂單狀態變為“處理中”時向管理員發送通知電子郵件的代碼: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 );}但它不起作用,因為當訂單狀態變為處理中時,管理員不會收到任何電子郵件。我認為我的代碼有問題。有什么幫助嗎?
1 回答

阿晨1998
TA貢獻2037條經驗 獲得超6個贊
您可以使用woocommerce_order_status_$STATUS_TRANSITION[to]復合鉤子將“處理”狀態轉換$STATUS_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 文件。它應該更好地工作。
- 1 回答
- 0 關注
- 187 瀏覽
添加回答
舉報
0/150
提交
取消