• Resolved Never Settle

    (@neversettle)


    I have created a custom Order Action in the Actions metabox drop-down on the Order edit page by hooking woocommerce_order_actions. Then I process the action by hooking woocommerce_order_action_MY_ACTION_NAME. That works fine.

    The issue is that part of that action updates the order status to reflect what was done with it. However, this triggers an infinite loop. It doesn’t matter what new status is set.

    Is this a bug? Or am I doing something wrong? It feels like a bug. WC’s extensive hooks and filters are fantastic, but this issue feels like the status change is triggering another action which then causes the cycle to repeat.

    Looking at the order notes, I can see multiple notes created where the statuses are being changed back and forth between the two (the current status at the time and the new status that the custom action is trying to set). I looked at WC_Order::update_status and it seemed like there might be an issue lurking there, but nothing specific jumped out at me.

    I also call some of the same code by hooking payment_complete which also updates the status, but that all works fine. If I manually call payment_complete() or let the action fire or manually call my code that updates the status it functions perfectly. But when I try to trigger the same code from the edit Order page via a custom Order Action in the Actions metabox, it goes into an infinite loop toggling the statuses between current and new as soon as I click the apply button.

    Anyone have any insights on how I can get the same thing done (custom code including a status update) from the Order Actions without triggering an infinite loop?

    Thanks in advance!

    https://wordpress.org/plugins/woocommerce/

Viewing 1 replies (of 1 total)
  • Thread Starter Never Settle

    (@neversettle)

    Nevermind. I would still love to understand the core cause with this, but in case anyone else runs into it, I was able to work around it by calling wp_set_post_terms directly in my custom order action, which didn’t trigger the hook loop but still achieved the same result to update the order status as part of the action.

Viewing 1 replies (of 1 total)
  • The topic ‘Infinite Loop using order->update_status from custom Order Action metabox action’ is closed to new replies.