• Resolved olehellhound

    (@olehellhound)


    Here’s the rundown-

    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. Here is the code:

    function wc_mark_sg_order_complete($order_id){
    	global $woocommerce;
    	if (!$order_id) die;
    	$order = new WC_Order($order_id);
    	//$order->payment_complete();
    	$order->update_status( 'completed' );
    
    	wp_safe_redirect( wp_get_referer() );
    }
    add_action('wp_woocommerce_sg-mark-order-complete', 'wc_mark_sg_order_complete');
    
    if(!empty($_GET["orderComplete"])){
    	do_action('wp_woocommerce_sg-mark-order-complete', $_GET["orderComplete"]);
    }

    This code works. 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.

    Thanks for any assistance! It is much appreciated!

    https://www.ads-software.com/plugins/woocommerce/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter olehellhound

    (@olehellhound)

    Update:

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

    $sg_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.

    Thanks again for any assistance.

    Thread Starter olehellhound

    (@olehellhound)

    Alrighty folks, 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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Update Status Timeout’ is closed to new replies.