• Resolved strigga

    (@strigga)


    I have implemented following code to set all my orders except bacs to complete after ordering:

    add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
    function custom_woocommerce_auto_complete_order( $order_id ) { 
        if ( ! $order_id ) {
            return;
        }
        
        $order = wc_get_order( $order_id );
        
        if($order->get_payment_method() == 'bacs'){
          $order->update_status( 'processing' );
        }else{
          $order->update_status( 'completed' );
        }
    }
    

    But at my recent 2 orders (which aren’nt bacs), the status is still “processing”. but I can’t figure out why?

    • This topic was modified 3 years, 3 months ago by strigga.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi @strigga

    Try this

    dd_action( 'woocommerce_thankyou', 'bacs_order_payment_processing_order_status', 10, 1 );
     
    function bacs_order_payment_processing_order_status( $order_id ) {
        if ( ! $order_id ) {
            return;
        }
    
        // Get an instance of the WC_Order object
        $order = new WC_Order( $order_id );
     
        if ( ( get_post_meta($order->id, '_payment_method', true) == 'bacs' )) {
            $order->update_status('processing');
        } else {
             $order->update_status('completed');
        }
    }

    Code goes in function.php file of your active child theme (or active theme). tested and works.

    Thanks
    Ahir Hemant

    Thread Starter strigga

    (@strigga)

    My code in the first post works too. At my past orders everything worked, but not at the latest 2 orders … and I can’t figure out why.

    Mirko P.

    (@rainfallnixfig)

    Hi @strigga,

    If the same payment method was setting your orders to “Completed” while now you see “Processing” status, it might be due to a recent change on your site, or a conflict after an update.

    You may want to run conflict testing to check if it’s working with all plugins disabled except for WooCommerce and with the default Storefront theme.

    You will find more details here: You can find a more detailed explanation on how to do a conflict test here: https://docs.woocommerce.com/document/how-to-test-for-conflicts/.

    Thanks.

    Mirko P.

    (@rainfallnixfig)

    Hi there,

    We haven’t heard from you in a while, so I’m going to mark this as resolved. Feel free to start a new thread if you have any more questions.

    Thread Starter strigga

    (@strigga)

    I can’t say why, but it only happened once and at the next order it worked again. I also sometimes get the order email 3 times … maybe a server problem?

    Hi @strigga

    It could be. If the problem does not recur, well and good. Or else please open up a new thread and we’ll be happy to help out.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘problem with automatically complete orders’ is closed to new replies.