Woocommerce update order status timeout?

I have created a plugin which displays all orders in a nice format for a bakery using Flexigrid. The display works just fine. The problem is that I have a button at the end of each order row that will allow the shop manager to update an order status. All this is in the admin panel.

The problem is the time it takes for the code to work. When I update an order status on the Woocommerce orders page, the status is updated near-instantly. When I use this function to update an order status, it will take exactly 60 seconds to complete. Something here is not ending the call to the database or something I feel like. While the script is running, the entire database is locked and I cannot load the website in any other tabs until the action is completed. The database puts the query in to “Sleep” mode, I’m not sure if this has anything to do with it or not.

Basically, I just need to figure out how to get the code to execute instantly instead of taking the timeout period of 60 seconds to complete.

I removed all that code and replaced my “Complete Order” link href to this variable:

Changed   
  1. $url = wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce-mark-order-complete&order_id=' . $the_order["orderid"] ), 'woocommerce-mark-order-complete' );

The same thing happened though. When I click the complete button in my plugin the script takes 60 seconds to execute but when I click the complete button from the WooCommerce orders page it will process instantly.

 

To fix this problem, it turns out that the emails for “Completed Orders” was causing the script to hang because I noticed the WooCommerce Orders page doing the same exact thing. I disabled email notices for Completed Orders and the script runs instantly.