Woocommerce disable automatic order status change

2019-04-16 02:39发布

问题:

I want to dissable this option:
Whenever someone makes and order on my site and the payment is successfull the order status automaticaly changes from pending to processing.

However I don`t want this feature to have enabled. Rather I want to do it manually when i proces the orders.

I found this function in the woocommerce which is making this feature possible. I don`t want to directly change it there but rather with some kind of php snippet which overrides this function.

Here is the function which i need to change : http://woocommerce.wp-a2z.org/oik_api/wc_orderpayment_complete/

PS: I just having a hard time to do it correctly.

回答1:

Add the following code to your functions.php file.function

ja_order_status( $order_status, $order_id ) {
    $order = new WC_Order( $order_id );

    if ( 'processing' == $order_status ) {
        return 'pending';
    }

    return $order_status;
}
add_filter( 'woocommerce_payment_complete_order_status', 'ja_order_status', 10, 2 );

Tested on WooCommerce with Storefront paid via Stripe test mode.



回答2:

Update

May be this payment_complete() is not involved in the process you are looking for. Alternatively, what you could try is the woocommerce_thankyou action hook instead:

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

    $order = new WC_Order( $order_id ); // Get an instance of the WC_Order object

    if ( $order->has_status( 'processing' ) )
            $order-> update_status( 'pending' )
}

You can use the same alternative hook: woocommerce_thankyou_{$order->get_payment_method()} (replacing $order->get_payment_method() by the payment method ID slug)

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

This code is tested on Woocommerce 3+ and works.


Using a custom function hooked in woocommerce_valid_order_statuses_for_payment_complete filter hook, where you will return the desired orders statuses that can be taken by the related function payment_complete() which is responsible of auto change the order status.

By default the array of order statuses in the filter is:

array( 'on-hold', 'pending', 'failed', 'cancelled' ).

And we can remove 'on-hold' order status this way:

add_filter( 'woocommerce_payment_complete_order_status', 'disable_auto_order_status', 10, 2 );
function disable_auto_order_status( $order_statuses, $order ) {
    $return array( 'pending', 'failed', 'cancelled' );
}

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

This code is tested on Woocommerce 3+ and works.