diff --git a/includes/api/class-wc-api-orders.php b/includes/api/class-wc-api-orders.php index 2b4a94ee137..93b721b06e6 100644 --- a/includes/api/class-wc-api-orders.php +++ b/includes/api/class-wc-api-orders.php @@ -356,9 +356,12 @@ class WC_API_Orders extends WC_API_Resource { * @return array */ public function create_order( $data ) { + global $wpdb; $data = isset( $data['order'] ) ? $data['order'] : array(); + $wpdb->query( 'START TRANSACTION' ); + try { // permission check @@ -463,10 +466,14 @@ class WC_API_Orders extends WC_API_Resource { do_action( 'woocommerce_api_create_order', $order->id, $data, $this ); + $wpdb->query( 'COMMIT' ); + return $this->get_order( $order->id ); } catch ( WC_API_Exception $e ) { + $wpdb->query( 'ROLLBACK' ); + return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } }