WooCommerce Code Reference

Controller extends AbstractController
in package

Orders Controller.

Table of Contents

CANNOT_CREATE  = 'cannot_create'
CANNOT_DELETE  = 'cannot_delete'
CANNOT_TRASH  = 'cannot_trash'
INVALID_ID  = 'invalid_id'
Shared error codes.
RESOURCE_EXISTS  = 'resource_exists'
TRASH_NOT_SUPPORTED  = 'trash_not_supported'
$item_schema  : OrderSchema
Schema class for this route.
$namespace  : string
Route namespace.
$post_type  : string
Post type used for orders.
$query_utils  : QueryUtils
Query utils class.
$rest_base  : string
Route base.
$schema  : array<string|int, mixed>
Cache for the item schema populated after calling get_item_schema().
$update_utils  : UpdateUtils
Update utils class.
create_item()  : WP_Error|WP_REST_Response
Create a single item.
create_item_permissions_check()  : WP_Error|bool
Check if a given request has access to create an item.
delete_item()  : WP_REST_Response|WP_Error
Delete a single item.
delete_item_permissions_check()  : bool|WP_Error
Check if a given request has access to delete an item.
get_collection_params()  : array<string|int, mixed>
Add default context collection params and filter the result. This does not inherit from WP_REST_Controller::get_collection_params because some endpoints do not paginate results.
get_item()  : WP_Error|WP_REST_Response
Get a single item.
get_item_permissions_check()  : WP_Error|bool
Check if a given request has access to read an item.
get_item_schema()  : array<string|int, mixed>
Get item schema, conforming to JSON Schema. Extended by routes.
get_items()  : WP_Error|WP_REST_Response
Get collection of orders.
get_items_permissions_check()  : WP_Error|bool
Check if a given request has access to read items.
prepare_item_for_response()  : WP_REST_Response|WP_Error
Prepares the item for the REST response. Controllers do not need to override this method as they can define a get_item_response method to prepare items. This method will take care of filter hooks.
register_routes()  : mixed
Register the routes for orders.
update_item()  : WP_Error|WP_REST_Response
Update a single item.
update_item_permissions_check()  : WP_Error|bool
Check if a given request has access to update an item.
get_authentication_error_by_method()  : WP_Error|false
Returns an authentication error for a given HTTP verb.
get_error_prefix()  : string
Get the error prefix for errors.
get_hook_prefix()  : string
Get the hook prefix for actions and filters.
get_item_response()  : array<string|int, mixed>
Prepare a single order object for response.
get_query_schema()  : array<string|int, mixed>
Get the collection args schema.
get_route_error_by_code()  : WP_Error
Get an error response for a given error code.
get_route_error_response()  : WP_Error
Get route response when something went wrong.
get_route_error_response_from_object()  : WP_Error
Get route response when something went wrong and the supplied error is a WP_Error.
get_schema()  : array<string|int, mixed>
Get the schema for the current resource. This use consumed by the AbstractController to generate the item schema after running various hooks on the response.
is_valid_order_for_request()  : bool
Check if an order is valid.
prepare_links()  : array<string|int, mixed>
Prepare links for the request.

Constants

Properties

Methods

create_item()

Create a single item.

public create_item(WP_REST_Request $request) : WP_Error|WP_REST_Response
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
WP_Error|WP_REST_Response

create_item_permissions_check()

Check if a given request has access to create an item.

public create_item_permissions_check(WP_REST_Request $request) : WP_Error|bool
Parameters
$request : WP_REST_Request

The request object.

Return values
WP_Error|bool

delete_item()

Delete a single item.

public delete_item(WP_REST_Request $request) : WP_REST_Response|WP_Error
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
WP_REST_Response|WP_Error

delete_item_permissions_check()

Check if a given request has access to delete an item.

public delete_item_permissions_check(WP_REST_Request $request) : bool|WP_Error
Parameters
$request : WP_REST_Request

The request object.

Return values
bool|WP_Error

get_collection_params()

Add default context collection params and filter the result. This does not inherit from WP_REST_Controller::get_collection_params because some endpoints do not paginate results.

public get_collection_params() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_item()

Get a single item.

public get_item(WP_REST_Request $request) : WP_Error|WP_REST_Response
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
WP_Error|WP_REST_Response

get_item_permissions_check()

Check if a given request has access to read an item.

public get_item_permissions_check(WP_REST_Request $request) : WP_Error|bool
Parameters
$request : WP_REST_Request

The request object.

Return values
WP_Error|bool

get_item_schema()

Get item schema, conforming to JSON Schema. Extended by routes.

public get_item_schema() : array<string|int, mixed>
Tags
since
10.2.0
Return values
array<string|int, mixed>The item schema.

get_items()

Get collection of orders.

public get_items(WP_REST_Request $request) : WP_Error|WP_REST_Response
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
WP_Error|WP_REST_Response

get_items_permissions_check()

Check if a given request has access to read items.

public get_items_permissions_check(WP_REST_Request $request) : WP_Error|bool
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
WP_Error|bool

prepare_item_for_response()

Prepares the item for the REST response. Controllers do not need to override this method as they can define a get_item_response method to prepare items. This method will take care of filter hooks.

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

WordPress representation of the item.

$request : WP_REST_Request

Request object.

Tags
since
10.2.0
Return values
WP_REST_Response|WP_ErrorResponse object on success, or WP_Error object on failure.

update_item()

Update a single item.

public update_item(WP_REST_Request $request) : WP_Error|WP_REST_Response
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
WP_Error|WP_REST_Response

update_item_permissions_check()

Check if a given request has access to update an item.

public update_item_permissions_check(WP_REST_Request $request) : WP_Error|bool
Parameters
$request : WP_REST_Request

The request object.

Return values
WP_Error|bool

get_authentication_error_by_method()

Returns an authentication error for a given HTTP verb.

protected get_authentication_error_by_method(string $method) : WP_Error|false
Parameters
$method : string

HTTP method.

Return values
WP_Error|falseWP Error object or false if no error is found.

get_error_prefix()

Get the error prefix for errors.

protected get_error_prefix() : string

Example: woocommerce_rest_api_v4_orders_

Tags
since
10.2.0
Return values
stringThe error prefix.

get_hook_prefix()

Get the hook prefix for actions and filters.

protected get_hook_prefix() : string

Example: woocommerce_rest_api_v4_orders_

Tags
since
10.2.0
Return values
stringThe hook prefix.

get_item_response()

Prepare a single order object for response.

protected get_item_response(WC_Order $order, WP_REST_Request $request) : array<string|int, mixed>
Parameters
$order : WC_Order

Order object.

$request : WP_REST_Request

Request object.

Return values
array<string|int, mixed>

get_route_error_by_code()

Get an error response for a given error code.

protected get_route_error_by_code(string $error_code) : WP_Error
Parameters
$error_code : string

The error code.

Return values
WP_ErrorWP Error object.

get_route_error_response()

Get route response when something went wrong.

protected get_route_error_response(string $error_code, string $error_message[, int $http_status_code = WP_Http::BAD_REQUEST ][, array<string|int, mixed> $additional_data = array() ]) : WP_Error
Parameters
$error_code : string

String based error code.

$error_message : string

User facing error message.

$http_status_code : int = WP_Http::BAD_REQUEST

HTTP status. Defaults to 400.

$additional_data : array<string|int, mixed> = array()

Extra data (key value pairs) to expose in the error response.

Tags
since
10.2.0
Return values
WP_ErrorWP Error object.

get_route_error_response_from_object()

Get route response when something went wrong and the supplied error is a WP_Error.

protected get_route_error_response_from_object(WP_Error $error_object[, int $http_status_code = WP_Http::BAD_REQUEST ][, array<string|int, mixed> $additional_data = array() ]) : WP_Error
Parameters
$error_object : WP_Error

The WP_Error object containing the error.

$http_status_code : int = WP_Http::BAD_REQUEST

HTTP status. Defaults to 400.

$additional_data : array<string|int, mixed> = array()

Extra data (key value pairs) to expose in the error response.

Tags
since
10.2.0
Return values
WP_ErrorWP Error object.

get_schema()

Get the schema for the current resource. This use consumed by the AbstractController to generate the item schema after running various hooks on the response.

protected get_schema() : array<string|int, mixed>
Return values
array<string|int, mixed>The full item schema.

Prepare links for the request.

protected prepare_links(mixed $item, WP_REST_Request $request, WP_REST_Response $response) : array<string|int, mixed>
Parameters
$item : mixed

WordPress representation of the item.

$request : WP_REST_Request

Request object.

$response : WP_REST_Response

Response object.

Return values
array<string|int, mixed>