简体   繁体   中英

Auto change order status from hold-on to processing in Woocommerce

I would like to change every order from woocommerce with the status 'HOLD-ON' to 'PROCESSING' with php .

I already tried to write a function in the functions.php file but I failed.

How can I auto change order status from "hold-on" to "processing" in Woocommerce?

To auto-process orders, you should try the following:

add_action( 'woocommerce_thankyou', 'woocommerce_auto_processing_orders');
function woocommerce_auto_processing_orders( $order_id ) {
    if ( ! $order_id )
        return;

    $order = wc_get_order( $order_id );

    // If order is "on-hold" update status to "processing"
    if( $order->has_status( 'on-hold' ) ) {
        $order->update_status( 'processing' );
    }
}

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

add_action('woocommerce_order_status_changed', 'ts_auto_complete_by_payment_method');

function ts_auto_complete_by_payment_method($order_id)
{

if ( ! $order_id ) {
return;
}

global $product;
$order = wc_get_order( $order_id );

if ($order->data['status'] == 'on-hold') {
$payment_method=$order->get_payment_method();
if ($payment_method!="COD")  // change payment method 
{
$order->update_status( 'processing' );
}}}

Add code to your child theme's functions.php file or via a plugin that allows custom functions to be added, such as the Code snippets plugin. Avoid adding custom code directly to your parent theme's functions.php file as this will be wiped entirely when you update the theme.

You could also change the “Completed” status to be another order status, like “Processing”

   **
* Auto Complete all WooCommerce orders.
*/
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 );
   $order->update_status( 'processing' );
} ```

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM