2

I need to make WooCommerce push payments made by check into the "processing" status rather than the "on hold" status. I tried the snippet below however it doesn't seem to have an effect.

Here is my code:

add_filter( 'woocommerce_payment_complete_order_status', 'sf_wc_autocomplete_paid_orders' );

function sf_wc_autocomplete_paid_orders( $order_status, $order_id ) {

$order = wc_get_order( $order_id );

if ($order->status == 'on-hold') {
    return 'processing';
}

return $order_status;
}

How can I achieve this?

Thanks.

DarkSpartan47
  • 153
  • 2
  • 16

3 Answers3

12

Here is the function you are looking at hooked in woocommerce_thankyou hook:

add_action( 'woocommerce_thankyou', 'cheque_payment_method_order_status_to_processing', 10, 1 );
function cheque_payment_method_order_status_to_processing( $order_id ) {
    if ( ! $order_id )
        return;

    $order = wc_get_order( $order_id );

    // Updating order status to processing for orders delivered with Cheque payment methods.
    if (  get_post_meta($order->id, '_payment_method', true) == 'cheque' )
        $order->update_status( 'processing' );
}

This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

This is tested and works.


Related thread: WooCommerce: Auto complete paid Orders (depending on Payment methods)

Community
  • 1
  • 1
LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • 2
    I'm surprised that the thank you page is the right hook, but I couldn't find anything better, so I think that's it. – helgatheviking Oct 07 '16 at 16:51
  • cheque is now called check so will this work? I will try it as well. – Abu Nooh Jun 21 '18 at 18:07
  • @AbuNooh I just checked now that and Cheque payment Id is still "cheque" just as before in Woocommerce last version. You can use `in_array()` function to be sure, this way: `if ( in_array( get_post_meta($order->id, '_payment_method', true), array( 'cheque','check') ) )` – LoicTheAztec Jun 21 '18 at 18:19
  • Yes that's perfect it works in the latest version of woocommerce. – Abu Nooh Jun 21 '18 at 20:07
  • Worked perfectly. I even changed it to a custom status using https://docs.woocommerce.com/document/woocommerce-order-status-manager/ – Dean Oakley Nov 21 '18 at 05:51
5

I didn't want to use the Thank You filter in case the order still got set to On Hold at a previous step, before changing it to my desired status in the filter (a custom status in my case, or Processing in yours). So I used the filter in the Cheque gateway:

add_filter( 'woocommerce_cheque_process_payment_order_status', 'myplugin_change_order_to_agent_processing', 10, 1 );
function myplugin_change_order_to_agent_processing($status){
    return 'agent-processing';
}

I hope this helps someone else out there to know that there is another option.

Maira Bay
  • 300
  • 5
  • 8
0

Previous answer from LoicTheAztec is outdated and gives error about accessing object fields directly on the order object.

Correct code should be

add_action( 'woocommerce_thankyou', 'cheque_payment_method_order_status_to_processing', 10, 1 );
function cheque_payment_method_order_status_to_processing( $order_id ) {
    if ( ! $order_id )
        return;

    $order = wc_get_order( $order_id );

    // Updating order status to processing for orders delivered with Cheque payment methods.
    if (  get_post_meta($order->get_id(), '_payment_method', true) == 'cheque' )
        $order->update_status( 'processing' );
}