WC_REST_Legacy_Orders_Controller::update_order()protectedWC 1.0

Deprecated from version 3.0.0. It is no longer supported and can be removed in future releases. It is recommended to replace this function with the same one.

Update order.

Method of the class: WC_REST_Legacy_Orders_Controller{}

No Hooks.

Return

Int|WP_Error.

Usage

// protected - for code of main (parent) or child class
$result = $this->update_order( $request );
$request(WP_REST_Request) (required)
Full details about the request.

Changelog

Deprecated since 3.0.0

WC_REST_Legacy_Orders_Controller::update_order() code WC 8.7.0

protected function update_order( $request ) {
	try {
		$order = $this->prepare_item_for_database( $request );
		$order->save();

		// Handle set paid.
		if ( $order->needs_payment() && true === $request['set_paid'] ) {
			$order->payment_complete( $request['transaction_id'] );
		}

		// If items have changed, recalculate order totals.
		if ( isset( $request['billing'] ) || isset( $request['shipping'] ) || isset( $request['line_items'] ) || isset( $request['shipping_lines'] ) || isset( $request['fee_lines'] ) || isset( $request['coupon_lines'] ) ) {
			$order->calculate_totals();
		}

		return $order->get_id();
	} catch ( WC_Data_Exception $e ) {
		return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
	} catch ( WC_REST_Exception $e ) {
		return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
	}
}