WooCommerce Code Reference

OrderFulfillmentsRestController extends RestApiControllerBase

OrderFulfillmentsRestController class file.

!> Note: This REST controller is only created for WC_Order type of entities, that allow !> managing fulfillments only for admins. Regular users can only view their fulfillments. !> !> If you are using another entity type for your fulfillments, you should create a new controller.

Table of Contents

$namespace  : string
Endpoint namespace.
$rest_base  : string
REST API base.
create_fulfillment()  : WP_REST_Response
Create a new fulfillment with the given data for the order.
delete_fulfillment()  : WP_REST_Response
Delete a specific fulfillment for the order.
delete_fulfillment_meta()  : WP_REST_Response
Delete the metadata for a specific fulfillment.
get_fulfillment()  : WP_REST_Response
Get a specific fulfillment for the order.
get_fulfillment_meta()  : WP_REST_Response
Get the metadata for a specific fulfillment.
get_fulfillments()  : WP_REST_Response
Get the fulfillments for the order.
get_tracking_number_details()  : WP_REST_Response
Get the tracking number details for a given tracking number, if possible.
register_routes()  : mixed
Register the routes for fulfillments.
update_fulfillment()  : WP_REST_Response
Update a specific fulfillment for the order.
update_fulfillment_meta()  : WP_REST_Response
Update the metadata for a specific fulfillment.
check_permission_for_fulfillments()  : bool|WP_Error
Permission check for REST API endpoints, given the request method.
check_request_source()  : string
Check the request source by inspecting headers or parameters.
get_rest_api_namespace()  : string
Get the WooCommerce REST API namespace for the class.
get_args_for_create_fulfillment()  : array<string|int, mixed>
Get the arguments for the create fulfillment endpoint.
get_args_for_delete_fulfillment()  : array<string|int, mixed>
Get the arguments for the delete fulfillment endpoint.
get_args_for_delete_fulfillment_meta()  : array<string|int, mixed>
Get the arguments for the delete fulfillment meta endpoint.
get_args_for_get_fulfillment()  : array<string|int, mixed>
Get the arguments for the get fulfillment endpoint.
get_args_for_get_fulfillment_meta()  : array<string|int, mixed>
Get the arguments for the get fulfillment meta endpoint.
get_args_for_get_fulfillments()  : array<string|int, mixed>
Get the arguments for the get order fulfillments endpoint.
get_args_for_get_tracking_number_details()  : array<string|int, mixed>
Get the arguments for the get tracking number details endpoint.
get_args_for_update_fulfillment()  : array<string|int, mixed>
Get the arguments for the update fulfillment endpoint.
get_args_for_update_fulfillment_meta()  : array<string|int, mixed>
Get the arguments for the update fulfillment meta endpoint.
get_read_schema_for_fulfillment()  : array<string|int, mixed>
Get the base schema for the fulfillment with a read context.
get_schema_for_create_fulfillment()  : array<string|int, mixed>
Get the schema for the create fulfillment endpoint.
get_schema_for_delete_fulfillment()  : array<string|int, mixed>
Get the schema for the delete fulfillment endpoint.
get_schema_for_delete_fulfillment_meta()  : array<string|int, mixed>
Get the schema for the delete fulfillment meta endpoint.
get_schema_for_get_fulfillment()  : array<string|int, mixed>
Get the schema for the get fulfillment endpoint.
get_schema_for_get_fulfillment_meta()  : array<string|int, mixed>
Get the schema for the get fulfillment meta endpoint.
get_schema_for_get_fulfillments()  : array<string|int, mixed>
Get the schema for the get order fulfillments endpoint.
get_schema_for_get_tracking_number_details()  : array<string|int, mixed>
Get the schema for the get tracking number details endpoint.
get_schema_for_meta_data()  : array<string|int, mixed>
Get the schema for the meta data.
get_schema_for_update_fulfillment()  : array<string|int, mixed>
Get the schema for the update fulfillment endpoint.
get_schema_for_update_fulfillment_meta()  : array<string|int, mixed>
Get the schema for the update fulfillment meta endpoint.
get_write_args_for_fulfillment()  : array<string|int, mixed>
Get the base args for the fulfillment with a write context.
maybe_track_tracking_added()  : void
Track fulfillment_tracking_added if tracking information was added or changed.
prepare_error_response()  : WP_REST_Response
Prepare an error response.
validate_fulfillment()  : mixed
Validate the fulfillment.

Properties

Methods

create_fulfillment()

Create a new fulfillment with the given data for the order.

public create_fulfillment(WP_REST_Request $request) : WP_REST_Response
Parameters
$request : WP_REST_Request

The request object.

Return values
WP_REST_ResponseThe created fulfillment, or an error if the request fails.

delete_fulfillment()

Delete a specific fulfillment for the order.

public delete_fulfillment(WP_REST_Request $request) : WP_REST_Response
Parameters
$request : WP_REST_Request

The request object.

Return values
WP_REST_ResponseThe deleted fulfillment, or an error if the request fails.

delete_fulfillment_meta()

Delete the metadata for a specific fulfillment.

public delete_fulfillment_meta(WP_REST_Request $request) : WP_REST_Response
Parameters
$request : WP_REST_Request

The request object.

Return values
WP_REST_ResponseThe deleted metadata for the fulfillment, or an error if the request fails.

get_fulfillment()

Get a specific fulfillment for the order.

public get_fulfillment(WP_REST_Request $request) : WP_REST_Response
Parameters
$request : WP_REST_Request

The request object.

Tags
throws
Exception

If the fulfillment is not found or is deleted.

Return values
WP_REST_ResponseThe fulfillment for the order, or an error if the request fails.

get_fulfillment_meta()

Get the metadata for a specific fulfillment.

public get_fulfillment_meta(WP_REST_Request $request) : WP_REST_Response
Parameters
$request : WP_REST_Request

The request object.

Return values
WP_REST_ResponseThe metadata for the fulfillment, or an error if the request fails.

get_fulfillments()

Get the fulfillments for the order.

public get_fulfillments(WP_REST_Request $request) : WP_REST_Response
Parameters
$request : WP_REST_Request

The request object.

Return values
WP_REST_ResponseThe fulfillments for the order, or an error if the request fails.

get_tracking_number_details()

Get the tracking number details for a given tracking number, if possible.

public get_tracking_number_details(WP_REST_Request $request) : WP_REST_Response
Parameters
$request : WP_REST_Request

The request object.

Return values
WP_REST_ResponseThe tracking number details, or an error if the request fails.

update_fulfillment()

Update a specific fulfillment for the order.

public update_fulfillment(WP_REST_Request $request) : WP_REST_Response
Parameters
$request : WP_REST_Request

The request object.

Return values
WP_REST_ResponseThe updated fulfillment, or an error if the request fails.

update_fulfillment_meta()

Update the metadata for a specific fulfillment.

public update_fulfillment_meta(WP_REST_Request $request) : WP_REST_Response
Parameters
$request : WP_REST_Request

The request object.

Return values
WP_REST_ResponseThe updated metadata for the fulfillment, or an error if the request fails.

check_permission_for_fulfillments()

Permission check for REST API endpoints, given the request method.

protected check_permission_for_fulfillments(WP_REST_Request $request) : bool|WP_Error

For all fulfillments methods that have an order_id, we need to be sure the user has permission to view the order. For all other methods, we check if the user is logged in as admin and has the required capability.

Parameters
$request : WP_REST_Request

The request for which the permission is checked.

Tags
throws
WP_Error

If the URL contains an order, but the order does not exist.

Return values
bool|WP_ErrorTrue if the current user has the capability, otherwise an "Unauthorized" error or False if no error is available for the request method.

check_request_source()

Check the request source by inspecting headers or parameters.

protected check_request_source(WP_REST_Request $request) : string
Parameters
$request : WP_REST_Request

The request object.

Tags
phpstan-ignore-next-line

missingType.generics

Return values
stringThe request source identifier.

get_write_args_for_fulfillment()

Get the base args for the fulfillment with a write context.

private get_write_args_for_fulfillment([bool $is_create = false ]) : array<string|int, mixed>
Parameters
$is_create : bool = false

Whether the args list is for a create request.

Return values
array<string|int, mixed>

maybe_track_tracking_added()

Track fulfillment_tracking_added if tracking information was added or changed.

private maybe_track_tracking_added(Fulfillment $fulfillment, WP_REST_Request $request[, array<string|int, mixed> $changes = array() ]) : void

For new fulfillments ($changes is empty), fires whenever a tracking number is present. For updates, only fires when tracking-related meta (_tracking_number, _shipment_provider, or _tracking_url) actually changed.

Parameters
$fulfillment : Fulfillment

The fulfillment object (after save).

$request : WP_REST_Request

The original request.

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

The changes from Fulfillment::get_changes(), empty for creates.

Tags
phpstan-ignore-next-line

missingType.generics

Return values
void

prepare_error_response()

Prepare an error response.

private prepare_error_response(string $code, string $message, int $status) : WP_REST_Response
Parameters
$code : string

The error code.

$message : string

The error message.

$status : int

The HTTP status code.

Return values
WP_REST_ResponseThe error response.