首页 文章

向WooCommerce中的待处理订单状态的管理员发送电子邮件通知

提问于
浏览
3

在WooCommerce中,当客户从购物车结账并提交订单时,如果未处理付款,则订单将设置为“待处理”付款 . 管理员未收到任何有关的电子邮件 .

我想向管理员发送电子邮件以获取此类订单 . 我该怎么做?

2 回答

  • 2

    UPDATE 2 (感谢CélineGarel,从 woocommerce_new_order 改为 woocommerce_checkout_order_processed

    当新订单 get a pending status 并且将自动触发"New Order"电子邮件通知时,将在所有可能情况下触发此代码:

    // New order notification only for "Pending" Order status
    add_action( 'woocommerce_checkout_order_processed', 'pending_new_order_notification', 20, 1 );
    function pending_new_order_notification( $order_id ) {
    
        // Get an instance of the WC_Order object
        $order = wc_get_order( $order_id );
    
        // Only for "pending" order status
        if( ! $order->has_status( 'pending' ) ) return;
    
        // Send "New Email" notification (to admin)
        WC()->mailer()->get_emails()['WC_Email_New_Order']->trigger( $order_id );
    }
    

    代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中 .

    此代码经过测试,适用于WooCommerce版本2.6.x和3 .


    一个更可定制的代码版本(如果需要),将使 pending Orders more visible

    // New order notification only for "Pending" Order status
    add_action( 'woocommerce_checkout_order_processed', 'pending_new_order_notification', 20, 1 );
    function pending_new_order_notification( $order_id ) {
        // Get an instance of the WC_Order object
        $order = wc_get_order( $order_id );
    
        // Only for "pending" order status
        if( ! $order->has_status( 'pending' ) ) return;
    
        // Get an instance of the WC_Email_New_Order object
        $wc_email = WC()->mailer()->get_emails()['WC_Email_New_Order'];
    
        ## -- Customizing Heading, subject (and optionally add recipients)  -- ##
        // Change Subject
        $wc_email->settings['subject'] = __('{site_title} - New customer Pending order ({order_number}) - {order_date}');
        // Change Heading
        $wc_email->settings['heading'] = __('New customer Pending Order'); 
        // $wc_email->settings['recipient'] .= ',name@email.com'; // Add email recipients (coma separated)
    
        // Send "New Email" notification (to admin)
        $wc_email->trigger( $order_id );
    }
    

    代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中 .

    此代码经过测试,适用于WooCommerce版本2.6.x和3 .

    在此版本中,您可以自定义电子邮件 Headers ,主题,添加收件人...

  • 7

    我已经尝试了 LoicTheAztec answer ,@ LoicTheAztec非常感谢您的优秀代码 .

    我刚刚将动作挂钩从 woocommerce_new_order 更改为 woocommerce_checkout_order_processed 以使其工作 .

    这是行动: add_action( 'woocommerce_checkout_order_processed', 'pending_new_order_notification', 20, 1 );

    希望有所帮助 .

相关问题