OrderFulfillmentsRestController
extends RestApiControllerBase
in package
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
$namespace
Endpoint namespace.
protected
string
$namespace
= 'wc/v3'
$rest_base
REST API base.
protected
string
$rest_base
= '/orders/(?P<order_id>[\d]+)/fulfillments'
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_Response — The 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_Response — The 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_Response — The 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
Return values
WP_REST_Response — The 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_Response — The 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_Response — The 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_Response — The tracking number details, or an error if the request fails.register_routes()
Register the routes for fulfillments.
public
register_routes() : mixed
Return values
mixed —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_Response — The 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_Response — The 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
Return values
bool|WP_Error — True 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
Return values
string — The request source identifier.get_rest_api_namespace()
Get the WooCommerce REST API namespace for the class.
protected
get_rest_api_namespace() : string
Return values
string —get_args_for_create_fulfillment()
Get the arguments for the create fulfillment endpoint.
private
get_args_for_create_fulfillment() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_args_for_delete_fulfillment()
Get the arguments for the delete fulfillment endpoint.
private
get_args_for_delete_fulfillment() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_args_for_delete_fulfillment_meta()
Get the arguments for the delete fulfillment meta endpoint.
private
get_args_for_delete_fulfillment_meta() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_args_for_get_fulfillment()
Get the arguments for the get fulfillment endpoint.
private
get_args_for_get_fulfillment() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_args_for_get_fulfillment_meta()
Get the arguments for the get fulfillment meta endpoint.
private
get_args_for_get_fulfillment_meta() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_args_for_get_fulfillments()
Get the arguments for the get order fulfillments endpoint.
private
get_args_for_get_fulfillments() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_args_for_get_tracking_number_details()
Get the arguments for the get tracking number details endpoint.
private
get_args_for_get_tracking_number_details() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_args_for_update_fulfillment()
Get the arguments for the update fulfillment endpoint.
private
get_args_for_update_fulfillment() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_args_for_update_fulfillment_meta()
Get the arguments for the update fulfillment meta endpoint.
private
get_args_for_update_fulfillment_meta() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_read_schema_for_fulfillment()
Get the base schema for the fulfillment with a read context.
private
get_read_schema_for_fulfillment() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_schema_for_create_fulfillment()
Get the schema for the create fulfillment endpoint.
private
get_schema_for_create_fulfillment() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_schema_for_delete_fulfillment()
Get the schema for the delete fulfillment endpoint.
private
get_schema_for_delete_fulfillment() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_schema_for_delete_fulfillment_meta()
Get the schema for the delete fulfillment meta endpoint.
private
get_schema_for_delete_fulfillment_meta() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_schema_for_get_fulfillment()
Get the schema for the get fulfillment endpoint.
private
get_schema_for_get_fulfillment() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_schema_for_get_fulfillment_meta()
Get the schema for the get fulfillment meta endpoint.
private
get_schema_for_get_fulfillment_meta() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_schema_for_get_fulfillments()
Get the schema for the get order fulfillments endpoint.
private
get_schema_for_get_fulfillments() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_schema_for_get_tracking_number_details()
Get the schema for the get tracking number details endpoint.
private
get_schema_for_get_tracking_number_details() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_schema_for_meta_data()
Get the schema for the meta data.
private
get_schema_for_meta_data() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_schema_for_update_fulfillment()
Get the schema for the update fulfillment endpoint.
private
get_schema_for_update_fulfillment() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_schema_for_update_fulfillment_meta()
Get the schema for the update fulfillment meta endpoint.
private
get_schema_for_update_fulfillment_meta() : array<string|int, mixed>
Return values
array<string|int, mixed> —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
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_Response — The error response.validate_fulfillment()
Validate the fulfillment.
private
validate_fulfillment(Fulfillment $fulfillment, int $fulfillment_id, int $order_id) : mixed
Parameters
- $fulfillment : Fulfillment
-
The fulfillment object.
- $fulfillment_id : int
-
The fulfillment ID.
- $order_id : int
-
The order ID.
