Woocommerce: Programmatically Updating Order Status Woocommerce: Programmatically Updating Order Status wordpress wordpress

Woocommerce: Programmatically Updating Order Status


The errors you are seeing are coming from the notification system. Your code appears able to update the status just fine. The Emogrify Class is used to generate inline CSS in an HTML template. You are likely seeing these errors because either A) you have overridden the "Completed order" email template and have created a parsing error or B) there is a WooCommerce add-on that is conflicting in some way with what you are doing.

To correct the issue, the first step will be to verify that it is the notification system by going into the admin under WooCommerce->Settings->Email->Completed order and un-checking the "Enable this email notification" box. Then save that and retest.

If your error goes away, then check your theme directory for an override of that template. It would be in <themename>/woocommerce/emails/customer-completed-order.php. If you have one, them rename it so it will not override anymore and reactivate the "Completed order" notification and see if using the default template corrects the issue.

If the issue persists with the default email notification template, then disable all of the WooCommerce add-ons you might have installed and retest. At this point, if it is working, you can re-enable them one-by-one until the issue returns. Once you have found the offending add-on, you will need to either adjust your code to allow for the add-on to not cause an issue or contact the add-on developer to address you issue.


I am not sure but you could try this trick using new WC_Order( $order_id );, to avoid the error:

// global $woocommerce; // in case of need…$order = wc_create_order($order_data);$order_id = $order->id; // moving this here$_order = new WC_Order( $order_id ); // here$_order->add_product( get_product( $membership_product_ids[0] ), 1 );$_order->set_address( $address, 'billing' );$_order->set_address( $address, 'shipping' );$_order->update_status('completed');

I agree this is a strange issue.