diff --git a/includes/class-wc-order.php b/includes/class-wc-order.php index 63fe7611422ac..eeb1e102f9c10 100755 --- a/includes/class-wc-order.php +++ b/includes/class-wc-order.php @@ -106,6 +106,9 @@ public function payment_complete( $transaction_id = '' ) { if ( ! $this->get_id() ) { return false; } + + wc_transaction_query( 'start' ); + do_action( 'woocommerce_pre_payment_complete', $this->get_id() ); if ( WC()->session ) { @@ -126,12 +129,17 @@ public function payment_complete( $transaction_id = '' ) { } else { do_action( 'woocommerce_payment_complete_order_status_' . $this->get_status(), $this->get_id() ); } + + wc_transaction_query( 'commit' ); } catch ( Exception $e ) { + wc_transaction_query( 'rollback' ); + $logger = wc_get_logger(); $logger->error( sprintf( 'Payment complete of order #%d failed!', $this->get_id() ), array( 'order' => $this, 'error' => $e, ) ); + $this->add_order_note( __( 'Payment complete event failed.', 'woocommerce' ) . ' ' . $e->getMessage() ); return false; } @@ -298,14 +306,20 @@ public function update_status( $new_status, $note = '', $manual = false ) { if ( ! $this->get_id() ) { return false; } + + wc_transaction_query( 'start' ); $this->set_status( $new_status, $note, $manual ); $this->save(); + wc_transaction_query( 'commit' ); } catch ( Exception $e ) { + wc_transaction_query( 'rollback' ); + $logger = wc_get_logger(); $logger->error( sprintf( 'Update status of order #%d failed!', $this->get_id() ), array( 'order' => $this, 'error' => $e, ) ); + $this->add_order_note( __( 'Update status event failed.', 'woocommerce' ) . ' ' . $e->getMessage() ); return false; }