WooCommerce Code Reference

Search results

WC_REST_Network_Orders_Controller extends WC_REST_Network_Orders_V2_Controller

REST API Network Orders controller class.

Table of Contents

$namespace Endpoint namespace. string
$namespace Endpoint namespace. string
$rest_base Route base. string
$post_type Post type. string
$hierarchical If object is hierarchical. bool
$request Stores the request. array
$public Controls visibility on frontend. string
register_routes() Register the routes for orders. mixed
get_public_item_schema() Retrieves the item's schema for display / public consumption purposes. array
network_orders_permissions_check() Does a permissions check for the proper requested blog bool
network_orders() Get a collection of orders from the requested blog id WP_REST_Response
network_orders_filter_args() Filters the post statuses to on hold and processing for the network order query. array
get_object() Get object. object
get_order_item_data() Expands an order item to get its data. array
get_formatted_item_data() Get formatted item data. array
prepare_object_for_response() Prepares the object for the REST response. WP_Error|WP_REST_Response
prepare_links() Prepare links for the request. array
prepare_objects_query() Prepare objects query. array
filter_writable_props() Only return writable props from schema. bool
prepare_object_for_database() Prepares one object for create or update operation. WP_Error|WC_Data
save_object() Save an object data. WC_Data|WP_Error
update_address() Update address. mixed
get_product_id() Gets the product ID from the SKU or posted ID. int
maybe_set_item_prop() Maybe set an item prop if the value was posted. mixed
maybe_set_item_props() Maybe set item props if the values were posted. mixed
maybe_set_item_meta_data() Maybe set item meta if posted. mixed
prepare_line_items() Create or update a line item. WC_Order_Item_Product
prepare_shipping_lines() Create or update an order shipping method. WC_Order_Item_Shipping
prepare_fee_lines() Create or update an order fee. WC_Order_Item_Fee
prepare_coupon_lines() Create or update an order coupon. WC_Order_Item_Coupon
set_item() Wrapper method to create/update order items. mixed
item_is_null() Helper method to check if the resource ID associated with the provided item is null. bool
get_order_statuses() Get order statuses without prefixes. array
get_item_schema() Get the Order's schema, conforming to JSON Schema. array
get_collection_params() Get the query params for collections of attachments. array
get_item_permissions_check() Check if a given request has access to read an item. WP_Error|bool
update_item_permissions_check() Check if a given request has access to update an item. WP_Error|bool
delete_item_permissions_check() Check if a given request has access to delete an item. bool|WP_Error
get_permalink() Get object permalink. string
get_item() Get a single item. WP_Error|WP_REST_Response
create_item() Create a single item. WP_Error|WP_REST_Response
update_item() Update a single post. WP_Error|WP_REST_Response
get_objects() Get objects. array
get_items() Get a collection of posts. WP_Error|WP_REST_Response
delete_item() Delete a single item. WP_REST_Response|WP_Error
get_items_permissions_check() Check if a given request has access to read items. WP_Error|bool
create_item_permissions_check() Check if a given request has access to create an item. WP_Error|bool
batch_items_permissions_check() Check if a given request has access batch create, update and delete items. bool|WP_Error
add_post_meta_fields() Add post meta fields. bool|WP_Error
delete_post() Delete post. mixed
prepare_items_query() Determine the allowed query_vars for a get_items() response and prepare for WP_Query. array
get_allowed_query_vars() Get all the WP Query vars that are allowed for the API request. array
update_post_meta_fields() Update post meta fields. bool|WP_Error
add_additional_fields_schema() Add the schema from additional fields to an schema array. array
get_endpoint_args_for_item_schema() Compatibility functions for WP 5.5, since custom types are not supported anymore. array
adjust_wp_5_5_datatype_compatibility() Change datatypes `date-time` to string, and `mixed` to composite of all built in types. This is required for maintaining forward compatibility with WP 5.5 since custom post types are not supported anymore. mixed
get_normalized_rest_base() Get normalized rest base. string
check_batch_limit() Check batch limit. bool|WP_Error
batch_items() Bulk create, update and delete items. array
validate_setting_text_field() Validate a text value for a text based setting. string
validate_setting_select_field() Validate select based settings. string|WP_Error
validate_setting_multiselect_field() Validate multiselect based settings. array|WP_Error
validate_setting_image_width_field() Validate image_width based settings. string|WP_Error
validate_setting_radio_field() Validate radio based settings. string|WP_Error
validate_setting_checkbox_field() Validate checkbox based settings. string|WP_Error
validate_setting_textarea_field() Validate textarea based settings. string
add_meta_query() Add meta query. array
get_public_batch_schema() Get the batch schema, conforming to JSON Schema. array
get_fields_for_response() Gets an array of fields to be included on the response. array

Properties

Methods

get_public_item_schema()

Retrieves the item's schema for display / public consumption purposes.

public get_public_item_schema( ) : array
Return values
array

Public item schema data.

network_orders_permissions_check()

Does a permissions check for the proper requested blog

public network_orders_permissions_check( $request : WP_REST_Request ) : bool
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
bool

$permission

network_orders()

Get a collection of orders from the requested blog id

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

Full details about the request.

Return values
WP_REST_Response

network_orders_filter_args()

Filters the post statuses to on hold and processing for the network order query.

public network_orders_filter_args( $args : array ) : array
Parameters
$args : array

Query args.

Return values
array

get_object()

Get object.

protected get_object( $id : int ) : object
Parameters
$id : int

Object ID.

Return values
object

WC_Data object or WP_Error object.

get_order_item_data()

Expands an order item to get its data.

protected get_order_item_data( $item : WC_Order_item ) : array
Parameters
$item : WC_Order_item

Order item data.

Return values
array

prepare_object_for_response()

Prepares the object for the REST response.

protected prepare_object_for_response( $object : WC_Data , $request : WP_REST_Request ) : WP_Error|WP_REST_Response
Parameters
$object : WC_Data

Object data.

$request : WP_REST_Request

Request object.

Tags
since
Return values
WP_Error|WP_REST_Response

Response object on success, or WP_Error object on failure.

prepare_links()

Prepare links for the request.

protected prepare_links( $post : WP_Post , $request : WP_REST_Request ) : array
Parameters
$post : WP_Post

Post object.

$request : WP_REST_Request

Request object.

Return values
array

Links for the given post.

prepare_objects_query()

Prepare objects query.

protected prepare_objects_query( $request : WP_REST_Request ) : array
Parameters
$request : WP_REST_Request

Full details about the request.

Tags
since
Return values
array

filter_writable_props()

Only return writable props from schema.

protected filter_writable_props( $schema : array ) : bool
Parameters
$schema : array

Schema.

Return values
bool

prepare_object_for_database()

Prepares one object for create or update operation.

protected prepare_object_for_database( $request : WP_REST_Request [, $creating : bool = false ] ) : WP_Error|WC_Data
Parameters
$request : WP_REST_Request

Request object.

$creating : bool = false

If is creating a new object.

Tags
since
Return values
WP_Error|WC_Data

The prepared item, or WP_Error object on failure.

save_object()

Save an object data.

protected save_object( $request : WP_REST_Request [, $creating : bool = false ] ) : WC_Data|WP_Error
Parameters
$request : WP_REST_Request

Full details about the request.

$creating : bool = false

If is creating a new object.

Tags
since
Return values
WC_Data|WP_Error

update_address()

Update address.

protected update_address( $order : WC_Order , $posted : array [, $type : string = 'billing' ] ) : mixed
Parameters
$order : WC_Order

Order data.

$posted : array

Posted data.

$type : string = 'billing'

Address type.

Return values
mixed

get_product_id()

Gets the product ID from the SKU or posted ID.

protected get_product_id( $posted : array [, $action : string = 'create' ] ) : int
Parameters
$posted : array

Request data.

$action : string = 'create'

'create' to add line item or 'update' to update it.

Tags
throws

When SKU or ID is not valid.

Return values
int

maybe_set_item_prop()

Maybe set an item prop if the value was posted.

protected maybe_set_item_prop( $item : WC_Order_Item , $prop : string , $posted : array ) : mixed
Parameters
$item : WC_Order_Item

Order item.

$prop : string

Order property.

$posted : array

Request data.

Return values
mixed

maybe_set_item_props()

Maybe set item props if the values were posted.

protected maybe_set_item_props( $item : WC_Order_Item , $props : string[] , $posted : array ) : mixed
Parameters
$item : WC_Order_Item

Order item data.

$props : string[]

Properties.

$posted : array

Request data.

Return values
mixed

prepare_line_items()

Create or update a line item.

protected prepare_line_items( $posted : array [, $action : string = 'create' ] [, $item : object = null ] ) : WC_Order_Item_Product
Parameters
$posted : array

Line item data.

$action : string = 'create'

'create' to add line item or 'update' to update it.

$item : object = null

Passed when updating an item. Null during creation.

Tags
throws

Invalid data, server error.

Return values
WC_Order_Item_Product

prepare_shipping_lines()

Create or update an order shipping method.

protected prepare_shipping_lines( $posted : array [, $action : string = 'create' ] [, $item : object = null ] ) : WC_Order_Item_Shipping
Parameters
$posted : array

$shipping Item data.

$action : string = 'create'

'create' to add shipping or 'update' to update it.

$item : object = null

Passed when updating an item. Null during creation.

Tags
throws

Invalid data, server error.

Return values
WC_Order_Item_Shipping

prepare_fee_lines()

Create or update an order fee.

protected prepare_fee_lines( $posted : array [, $action : string = 'create' ] [, $item : object = null ] ) : WC_Order_Item_Fee
Parameters
$posted : array

Item data.

$action : string = 'create'

'create' to add fee or 'update' to update it.

$item : object = null

Passed when updating an item. Null during creation.

Tags
throws

Invalid data, server error.

Return values
WC_Order_Item_Fee

prepare_coupon_lines()

Create or update an order coupon.

protected prepare_coupon_lines( $posted : array [, $action : string = 'create' ] [, $item : object = null ] ) : WC_Order_Item_Coupon
Parameters
$posted : array

Item data.

$action : string = 'create'

'create' to add coupon or 'update' to update it.

$item : object = null

Passed when updating an item. Null during creation.

Tags
throws

Invalid data, server error.

Return values
WC_Order_Item_Coupon

set_item()

Wrapper method to create/update order items.

protected set_item( $order : WC_Order , $item_type : string , $posted : array ) : mixed

When updating, the item ID provided is checked to ensure it is associated with the order.

Parameters
$order : WC_Order

order object.

$item_type : string

The item type.

$posted : array

item provided in the request body.

Tags
throws

If item ID is not associated with order.

Return values
mixed

item_is_null()

Helper method to check if the resource ID associated with the provided item is null.

protected item_is_null( $item : array ) : bool

Items can be deleted by setting the resource ID to null.

Parameters
$item : array

Item provided in the request body.

Return values
bool

True if the item resource ID is null, false otherwise.

get_collection_params()

Get the query params for collections of attachments.

public get_collection_params( ) : array
Return values
array

get_item_permissions_check()

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

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

Full details about the request.

Return values
WP_Error|bool

update_item_permissions_check()

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

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

Full details about the request.

Return values
WP_Error|bool

delete_item_permissions_check()

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

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

Full details about the request.

Return values
bool|WP_Error

get_permalink()

Get object permalink.

protected get_permalink( $object : object ) : string
Parameters
$object : object

Object.

Return values
string

get_item()

Get a single item.

public get_item( $request : WP_REST_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()

Create a single item.

public create_item( $request : WP_REST_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()

Update a single post.

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

Full details about the request.

Return values
WP_Error|WP_REST_Response

get_objects()

Get objects.

protected get_objects( $query_args : array ) : array
Parameters
$query_args : array

Query args.

Tags
since
Return values
array

get_items()

Get a collection of posts.

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

Full details about the request.

Return values
WP_Error|WP_REST_Response

delete_item()

Delete a single item.

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

Full details about the request.

Return values
WP_REST_Response|WP_Error

get_items_permissions_check()

Check if a given request has access to read items.

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

Full details about the request.

Return values
WP_Error|bool

create_item_permissions_check()

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

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

Full details about the request.

Return values
WP_Error|bool

batch_items_permissions_check()

Check if a given request has access batch create, update and delete items.

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

Full details about the request.

Return values
bool|WP_Error

add_post_meta_fields()

Add post meta fields.

protected add_post_meta_fields( $post : WP_Post , $request : WP_REST_Request ) : bool|WP_Error
Parameters
$post : WP_Post

Post Object.

$request : WP_REST_Request

WP_REST_Request Object.

Return values
bool|WP_Error

delete_post()

Delete post.

protected delete_post( $post : WP_Post ) : mixed
Parameters
$post : WP_Post

Post object.

Return values
mixed

prepare_items_query()

Determine the allowed query_vars for a get_items() response and prepare for WP_Query.

protected prepare_items_query( [ $prepared_args : array = array() ] [, $request : WP_REST_Request = null ] ) : array
Parameters
$prepared_args : array = array()

Prepared arguments.

$request : WP_REST_Request = null

Request object.

Return values
array

$query_args

get_allowed_query_vars()

Get all the WP Query vars that are allowed for the API request.

protected get_allowed_query_vars( ) : array
Return values
array

update_post_meta_fields()

Update post meta fields.

protected update_post_meta_fields( $post : WP_Post , $request : WP_REST_Request ) : bool|WP_Error
Parameters
$post : WP_Post

Post object.

$request : WP_REST_Request

Request object.

Return values
bool|WP_Error

add_additional_fields_schema()

Add the schema from additional fields to an schema array.

protected add_additional_fields_schema( $schema : array ) : array

The type of object is inferred from the passed schema.

Parameters
$schema : array

Schema array.

Return values
array

get_endpoint_args_for_item_schema()

Compatibility functions for WP 5.5, since custom types are not supported anymore.

public get_endpoint_args_for_item_schema( [ $method : string = WP_REST_Server::CREATABLE ] ) : array

See @link https://core.trac.wordpress.org/changeset/48306

Parameters
$method : string = WP_REST_Server::CREATABLE

Optional. HTTP method of the request.

Return values
array

Endpoint arguments.

adjust_wp_5_5_datatype_compatibility()

Change datatypes `date-time` to string, and `mixed` to composite of all built in types. This is required for maintaining forward compatibility with WP 5.5 since custom post types are not supported anymore.

protected adjust_wp_5_5_datatype_compatibility( $endpoint_args : array ) : mixed

See @link https://core.trac.wordpress.org/changeset/48306

We still use the 'mixed' type, since if we convert to composite type everywhere, it won't work in 5.4 anymore because they require to define the full schema.

Parameters
$endpoint_args : array

Schema with datatypes to convert.

Return values
mixed

Schema with converted datatype.

get_normalized_rest_base()

Get normalized rest base.

protected get_normalized_rest_base( ) : string
Return values
string

check_batch_limit()

Check batch limit.

protected check_batch_limit( $items : array ) : bool|WP_Error
Parameters
$items : array

Request items.

Return values
bool|WP_Error

batch_items()

Bulk create, update and delete items.

public batch_items( $request : WP_REST_Request ) : array
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
array

Of WP_Error or WP_REST_Response.

validate_setting_text_field()

Validate a text value for a text based setting.

public validate_setting_text_field( $value : string , $setting : array ) : string
Parameters
$value : string

Value.

$setting : array

Setting.

Tags
since
Return values
string

validate_setting_select_field()

Validate select based settings.

public validate_setting_select_field( $value : string , $setting : array ) : string|WP_Error
Parameters
$value : string

Value.

$setting : array

Setting.

Tags
since
Return values
string|WP_Error

validate_setting_multiselect_field()

Validate multiselect based settings.

public validate_setting_multiselect_field( $values : array , $setting : array ) : array|WP_Error
Parameters
$values : array

Values.

$setting : array

Setting.

Tags
since
Return values
array|WP_Error

validate_setting_image_width_field()

Validate image_width based settings.

public validate_setting_image_width_field( $values : array , $setting : array ) : string|WP_Error
Parameters
$values : array

Values.

$setting : array

Setting.

Tags
since
Return values
string|WP_Error

validate_setting_radio_field()

Validate radio based settings.

public validate_setting_radio_field( $value : string , $setting : array ) : string|WP_Error
Parameters
$value : string

Value.

$setting : array

Setting.

Tags
since
Return values
string|WP_Error

validate_setting_checkbox_field()

Validate checkbox based settings.

public validate_setting_checkbox_field( $value : string , $setting : array ) : string|WP_Error
Parameters
$value : string

Value.

$setting : array

Setting.

Tags
since
Return values
string|WP_Error

validate_setting_textarea_field()

Validate textarea based settings.

public validate_setting_textarea_field( $value : string , $setting : array ) : string
Parameters
$value : string

Value.

$setting : array

Setting.

Tags
since
Return values
string

add_meta_query()

Add meta query.

protected add_meta_query( $args : array , $meta_query : array ) : array
Parameters
$args : array

Query args.

$meta_query : array

Meta query.

Tags
since
Return values
array

get_public_batch_schema()

Get the batch schema, conforming to JSON Schema.

public get_public_batch_schema( ) : array
Return values
array

get_fields_for_response()

Gets an array of fields to be included on the response.

public get_fields_for_response( $request : WP_REST_Request ) : array

Included fields are based on item schema and _fields= request argument. Updated from WordPress 5.3, included into this class to support old versions.

Parameters
$request : WP_REST_Request

Full details about the request.

Tags
since
Return values
array

Fields to be included in the response.

Back to the top