WooCommerce Code Reference

CheckoutTrait

CheckoutTrait

Shared functionality for checkout route.

Table of Contents

prepare_item_for_response()  : WP_REST_Response
Prepare a single item for response. Handles setting the status based on the payment result.
get_request_payment_data()  : array<string|int, mixed>
Gets and formats payment request data.
get_request_payment_method_id()  : string
Gets the chosen payment method ID from the request.
get_request_payment_method_title()  : string
Gets the chosen payment method title from the request.
persist_additional_fields_for_order()  : mixed
Persist additional fields for the order after validating them.
process_payment()  : mixed
Fires an action hook instructing active payment gateways to process the payment for an order and provide a result.
process_without_payment()  : mixed
For orders which do not require payment, just update status.
update_order_from_request()  : mixed
Update the current order using the posted values from the request.

Methods

prepare_item_for_response()

Prepare a single item for response. Handles setting the status based on the payment result.

public prepare_item_for_response(mixed $item, WP_REST_Request $request) : WP_REST_Response
Parameters
$item : mixed

Item to format to schema.

$request : WP_REST_Request

Request object.

Return values
WP_REST_Response$response Response data.

get_request_payment_data()

Gets and formats payment request data.

private get_request_payment_data(WP_REST_Request $request) : array<string|int, mixed>
Parameters
$request : WP_REST_Request

Request object.

Return values
array<string|int, mixed>

get_request_payment_method_id()

Gets the chosen payment method ID from the request.

private get_request_payment_method_id(WP_REST_Request $request) : string
Parameters
$request : WP_REST_Request

Request object.

Tags
throws
RouteException

On error.

Return values
string

get_request_payment_method_title()

Gets the chosen payment method title from the request.

private get_request_payment_method_title(WP_REST_Request $request) : string
Parameters
$request : WP_REST_Request

Request object.

Tags
throws
RouteException

On error.

Return values
string

persist_additional_fields_for_order()

Persist additional fields for the order after validating them.

private persist_additional_fields_for_order(WP_REST_Request $request) : mixed
Parameters
$request : WP_REST_Request

Full details about the request.

Tags
throws
RouteException

On error.

Return values
mixed

process_payment()

Fires an action hook instructing active payment gateways to process the payment for an order and provide a result.

private process_payment(WP_REST_Request $request, PaymentResult $payment_result) : mixed
Parameters
$request : WP_REST_Request

Request object.

$payment_result : PaymentResult

Payment result object.

Tags
throws
RouteException

On error.

Return values
mixed

process_without_payment()

For orders which do not require payment, just update status.

private process_without_payment(WP_REST_Request $request, PaymentResult $payment_result) : mixed
Parameters
$request : WP_REST_Request

Request object.

$payment_result : PaymentResult

Payment result object.

Return values
mixed

update_order_from_request()

Update the current order using the posted values from the request.

private update_order_from_request(WP_REST_Request $request) : mixed
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
mixed