Updating Woocommerce Orders Programmatically

I have an eCommerce site running Woocommerce on top of WordPress, and the company running it has changed there shipping system to an external company who stores the products in their warehouse and ships the products when they are bought.

In terms of automation, downloading information on new orders and sending it to the shipping company is fine, but when they respond to me with an XML of the orders sent and the associated tracking numbers, I need to be able to have a system that automatically updates the orders (including sending out the emails necessary). However, the only way I currently know how to do that is to update the MySQL database. But with that method, the automated email system is overridden and ignored.

Read More

Does anyone know how I can update orders statues and other information programmatically, which would allow Woocommerce’s internal functions to be executed in the same way as manually logging into the admin side and updating the order?

Related posts

Leave a Reply

1 comment

  1. Found a solution to this yet?

    The code below works to mark an order as complete, but does not execute other actions as you describe in the admin

    // create a new checkout instance and order id
    $checkout = new WC_Checkout();
    $this_order_id = $checkout->create_order();
    
    $order = new WC_Order($this_order_id);
    $order->update_status('completed');