DrMTR
DrMTR

Reputation: 509

Send customer on-hold order notification once order is placed in Woocommerce 3.3

I have this issue. I using Woocommerce 3.3.3 in this moment in my site and noticed one weird issue. After customer placed order, their order is stuck on "On Hold" into Woocommerce orders.

on hold status

and customer dont get any order confirmation mail. When go to order and move status on order from "On Hold" to "Processing" customer is getting Order Confirmation mail, that should be automatically. Searched, and found this "fix":

add_filter( ‘woocommerce_defer_transactional_emails’, ‘__return_false’ );

to be placed into functions.php, but seems that dont changed nothing. Anyone with similar issue?

Upvotes: 2

Views: 4932

Answers (2)

svelandiag
svelandiag

Reputation: 4320

Just to point out:

The solution @LoicTheAztec mentioned works:

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 );
}

However there's an issue with this solution, at the time woocommerce_new_orderhook is called the order hasn't been fully created yet, so as result in the email notification the order items are not displayed. Use the following hook instead:

    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 );
     }

At the time woocommerce_checkout_order_processed is called the order items are already available for your email.

Upvotes: 0

LoicTheAztec
LoicTheAztec

Reputation: 254362

Try the following instead:

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 );
}

To change "on-hold" paid orders to "processing" use that:

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' );
    }
}

Code goes in function.php file of your active child theme (or active theme). It should work.

Upvotes: 1

Related Questions