Set WooCommerce Order status when order is created from processing to pending

advert

WooCommerce is the most popular WordPress e-commerce plugin in the world, powering more than 30% of all online stores. Join our YouTube channel learn everything you need to know about WooCommerce, WordPress, and e-commerce. Being an open source and more advanced creative programmers, you get there are many features that are requested by our client or you find you need most.

WooCommerce order status set to “pending” instead of “processing” once the orders is placed.

See the attached post for more

Attached is a Set WooCommerce Order status when order is created from processing to pending YouTube tutorial

YouTube tutorial will be available soon.

Copy and paste the code to add the feature to your ecommerce website.

add_action( 'woocommerce_checkout_order_processed', 'changing_order_status_before_payment', 10, 3 );
function changing_order_status_before_payment( $order_id, $posted_data, $order ){
    $order->update_status( 'pending' );
}

Apparently each payment method (and payment gateways) are setting the order status (depending on the transaction response for payment gateways)…

For Cash on delivery payment method, this can be tweaked using a dedicated filter hook, see:

You can also update the status using woocommerce_thankyou hook:

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

    $order = wc_get_order( $order_id );

    if( $order->get_status() == 'processing' )
        $order->update_status( 'pending' );
}
What if it previous code don’t work for you? Delete and use the code. This condition that prevents the status from being changed involuntarily by the client in case of refreshing the page, after 3 minutes of the initial change:
add_action( 'woocommerce_thankyou', 'woocommerce_thankyou_change_order_status', 10, 1 );
function woocommerce_thankyou_change_order_status( $order_id ){
    if( ! $order_id ) return;

    $order = wc_get_order( $order_id );

    $time_order     = strtotime($order->get_date_created());
    $time_current   = time();
    $time_interval  = $time_current - $time_order;

    //Case refresh page after 3 minutes at order, no changed status
    if( $order->get_status() == 'processing' && $time_interval < 180 ) {
        $order->update_status( 'pending' );
    }
}

se code snippet free plugin from wordpress.org plugin repository.

You many also like to read: WooCommerce Order Status ( Autocomplete paid WooCommerce orders)

advert:

Support us:

1
0
Would love your thoughts, please comment.x
()
x

Login To Access Code Snippet:

Stay UpTo Date with Latest Post And news: