【问题标题】:Send customer on-hold order notification once order is placed in Woocommerce 3.3在 Woocommerce 3.3 中下订单后发送客户暂停订单通知
【发布时间】:2018-03-16 11:48:51
【问题描述】:

我有这个问题。我此时在我的网站上使用 Woocommerce 3.3.3 并注意到一个奇怪的问题。客户下订单后,他们的订单在 Woocommerce 订单中处于“暂停”状态。

并且客户没有收到任何订单确认邮件。当去订单并将订单状态从“保留”移动到“处理中”时,客户正在收到订单确认邮件,这应该是自动的。搜索,发现这个“fix”:

add_filter( ‘woocommerce_defer_transactional_emails’, ‘__return_false’ );

被放入functions.php,但似乎并没有改变什么。有人有类似问题吗?

【问题讨论】:

    标签: php wordpress woocommerce orders email-notifications


    【解决方案1】:

    请尝试以下方法:

    add_action('woocommerce_new_order', 'new_order_on_hold_notification', 30, 1 );
    function new_order_on_hold_notification( $order_id ) {
        $order = wc_get_order( $order_id );
    
        // Only for on hold new orders
        if( ! $order->has_status('on-hold') )
            return; // Exit
    
        // Send Customer On-Hold Order notification
        WC()->mailer()->get_emails()['WC_Email_Customer_On_Hold_Order']->trigger( $order_id );
    }
    

    要将“暂停”已付款订单更改为“正在处理”,请使用:

    add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_prrocessing_paid_order', 10, 1 );
    function custom_woocommerce_auto_prrocessing_paid_order( $order_id ) {
        if ( ! $order_id )
           return;
    
        $order = wc_get_order( $order_id );
    
        // No updated status for orders delivered with Bank wire, Cash on delivery and Cheque payment methods.
        if ( in_array( $order->get_payment_method(), array( 'bacs', 'cod', 'cheque', '' ) ) ) {
            return;
        } 
        // "Processing" updated status for paid Orders with all others payment methods
        else {
            if( $order->has_status('on-hold') )
                $order->update_status( 'processing' );
        }
    }
    

    代码进入您的活动子主题(或活动主题)的 function.php 文件中。它应该可以工作。

    【讨论】:

    • 您好,将您的代码从活动主题插入到 functions.php 中,然后再次尝试下订单。下单后,订单仍停留在“暂停”状态。见图片:i.imgur.com/9wyP9GF.png?1 另外我在你的代码中看到你发送保留邮件,但我认为这一定是处理订单吗? Woo 后端也启用了保留邮件。 i.imgur.com/6fMs6cM.png?1
    • @JoeKooker 不适用于从网关下达的“支票”、“货到付款”或“银行电汇”订单,这些订单应手动从“暂停”设置为“处理”(或“已完成”)。 我的代码只是在下订单时向客户发送一封电子邮件通知,该订单处于“暂停”状态(您在问题中提出的内容) ...所以您想要什么(因为您的问题并不清楚),您只想将已付款订单从暂停更改为处理中?
    • 是的,抱歉,我的标题可能不清楚。我想 。是的,我想在用户下订单时收到新的订单确认邮件。就这样。目前暂未收到任何邮件。
    • @SsouLlesS 当使用WC_Order 方法get_status()set_status()has_status() 时,您不需要在订单状态信息前使用wc-
    • @SsouLlesS 抱歉,是的,即使您添加了答案,因为我的答案已被接受。而这一事实是由于 2018 年以来 woocommerce 的变化。
    【解决方案2】:

    只是指出:

    @LoicTheAztec 提到的解决方案有效:

    add_action('woocommerce_new_order', 'new_order_on_hold_notification', 30, 1 );
    function new_order_on_hold_notification( $order_id ) {
        $order = wc_get_order( $order_id );
    
        // Only for on hold new orders
        if( ! $order->has_status('on-hold') )
            return; // Exit
    
        // Send Customer On-Hold Order notification
        WC()->mailer()->get_emails()['WC_Email_Customer_On_Hold_Order']->trigger( $order_id );
    }
    

    但是,此解决方案存在问题,在调用 woocommerce_new_orderhook 时,订单尚未完全创建,因此在电子邮件通知中未显示订单商品。请改用以下钩子:

        add_action('woocommerce_checkout_order_processed', 'new_order_on_hold_notification');   
        function new_order_on_hold_notification( $order_id ) {
                        $order = wc_get_order( $order_id );
    
                        // Only for on hold new orders
                        if( ! $order->has_status('on-hold') )
                            return; // Exit
    
                        // Send Customer On-Hold Order notification
                        WC()->mailer()->get_emails()['WC_Email_Customer_On_Hold_Order']->trigger( $order_id );
         }
    

    在调用woocommerce_checkout_order_processed 时,订单商品已经可以通过您的电子邮件收到。

    【讨论】:

      猜你喜欢
      • 2018-09-19
      • 1970-01-01
      • 2019-07-11
      • 2019-05-10
      • 1970-01-01
      • 2018-10-24
      • 2021-02-09
      • 2014-03-09
      • 1970-01-01
      相关资源
      最近更新 更多