Automattic\WooCommerce\StoreApi\Routes\V1
CheckoutOrder::get_route_post_response()
Process an order.
- Process Request
- Process Customer
- Validate Order
- Process Payment
Method of the class: CheckoutOrder{}
Hooks from the method
Return
\WP_REST_Response
.
Usage
// protected - for code of main (parent) or child class $result = $this->get_route_post_response( $request );
- $request(\WP_REST_Request) (required)
- Request object.
CheckoutOrder::get_route_post_response() CheckoutOrder::get route post response code WC 9.6.0
protected function get_route_post_response( \WP_REST_Request $request ) { $order_id = absint( $request['id'] ); $this->order = wc_get_order( $order_id ); if ( ! $this->order || ! $this->order->needs_payment() ) { return new \WP_Error( 'invalid_order_update_status', __( 'This order cannot be paid for.', 'woocommerce' ) ); } /** * Process request data. * * Note: Customer data is persisted from the request first so that OrderController::update_addresses_from_cart * uses the up to date customer address. */ $this->update_billing_address( $request ); $this->update_order_from_request( $request ); /** * Process customer data. * * Update order with customer details, and sign up a user account as necessary. */ $this->process_customer( $request ); /** * Validate order. * * This logic ensures the order is valid before payment is attempted. */ $this->order_controller->validate_order_before_payment( $this->order ); /** * Fires before an order is processed by the Checkout Block/Store API. * * This hook informs extensions that $order has completed processing and is ready for payment. * * This is similar to existing core hook woocommerce_checkout_order_processed. We're using a new action: * - To keep the interface focused (only pass $order, not passing request data). * - This also explicitly indicates these orders are from checkout block/StoreAPI. * * @since 7.2.0 * * @see https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3238 * @example See docs/examples/checkout-order-processed.md * @param \WC_Order $order Order object. */ do_action( 'woocommerce_store_api_checkout_order_processed', $this->order ); /** * Process the payment and return the results. */ $payment_result = new PaymentResult(); if ( $this->order->needs_payment() ) { $this->process_payment( $request, $payment_result ); } else { $this->process_without_payment( $request, $payment_result ); } return $this->prepare_item_for_response( (object) [ 'order' => wc_get_order( $this->order ), 'payment_result' => $payment_result, ], $request ); }