在Woocommerce 3.3

时间:2018-03-16 11:48:51

标签: php wordpress woocommerce orders email-notifications

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

on hold status

并且客户没有收到任何订单确认邮件。当订单并按顺序从“暂停”移动到“处理”时,客户正在获取订单确认邮件,该邮件应该是自动的。搜索过,发现这个“fix”:

add_filter( ‘woocommerce_defer_transactional_emails’, ‘__return_false’ );

放入functions.php,但似乎没有改变任何东西。有类似问题的人吗?

2 个答案:

答案 0 :(得分: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文件中。它应该工作。

答案 1 :(得分:0)

仅需指出:

@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_order挂钩时,尚未完全创建订单,因此,在电子邮件通知中未显示订单项。请使用以下挂钩:

    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时,订单项已可用于您的电子邮件。

相关问题