I’m trying to update order status when a Store Manager clicks ‘Completed’.

I’m doing this because I want to check something (if a ‘key’ is present) on ‘Completed’. If the condition is not met, then I want to set the order back to ‘Processing’

The problem: using the hook ‘woocommerce_order_status_completed’ I get an infinite loop.

Here is the function simplified. This triggers the issue. Any thoughts why I’m getting a runaway loop?

add_action( 'woocommerce_order_status_completed', 'xcsn_woocommerce_order_status_completed' );
function xcsn_woocommerce_order_status_completed ( $order_id ) {
    $order = new WC_Order( $order_id );
    $order->update_status( 'processing', 'Set to Processing because Keys were not available' );
    // Surely the above means the hook 'woocommerce_order_status_completed' should only be triggered once?
}

Read more here: WooCommerce update_status() is causing infinite loop in hook


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , , ,

Wordpress related questions and answers: