WC_REST_Order_Refunds_V2_Controller
extends WC_REST_Orders_V2_Controller
in package
REST API Order Refunds controller class.
Tags
Table of Contents
- $hierarchical : bool
- If object is hierarchical.
- $namespace : string
- Endpoint namespace.
- $post_type : string
- Post type.
- $public : string
- Controls visibility on frontend.
- $request : array
- Stores the request.
- $rest_base : string
- Route base.
- __construct() : mixed
- Order refunds actions.
- batch_items() : array
- Bulk create, update and delete items.
- batch_items_permissions_check() : bool|WP_Error
- Check if a given request has access batch create, update and delete items.
- 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
- Get the query params for collections.
- get_endpoint_args_for_item_schema() : array
- Compatibility functions for WP 5.5, since custom types are not supported anymore.
- get_fields_for_response() : array
- Gets an array of fields to be included on the response.
- 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
- Get the Order's schema, conforming to JSON Schema.
- get_items() : WP_Error|WP_REST_Response
- Get a collection of posts.
- get_items_permissions_check() : WP_Error|bool
- Check if a given request has access to read items.
- get_public_batch_schema() : array
- Get the batch schema, conforming to JSON Schema.
- prepare_object_for_response() : WP_Error|WP_REST_Response
- Prepare a single order output for response.
- register_routes() : mixed
- Register the routes for order refunds.
- update_item() : WP_Error|WP_REST_Response
- Update a single post.
- update_item_permissions_check() : WP_Error|bool
- Check if a given request has access to update an item.
- validate_setting_checkbox_field() : string|WP_Error
- Validate checkbox based settings.
- validate_setting_image_width_field() : string|WP_Error
- Validate image_width based settings.
- validate_setting_multiselect_field() : array|WP_Error
- Validate multiselect based settings.
- validate_setting_radio_field() : string|WP_Error
- Validate radio based settings.
- validate_setting_select_field() : string|WP_Error
- Validate select based settings.
- validate_setting_text_field() : string
- Validate a text value for a text based setting.
- validate_setting_textarea_field() : string
- Validate textarea based settings.
- add_additional_fields_schema() : array
- Add the schema from additional fields to an schema array.
- add_meta_query() : array
- Add meta query.
- add_post_meta_fields() : bool|WP_Error
- Add post meta fields.
- adjust_wp_5_5_datatype_compatibility() : mixed
- 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.
- check_batch_limit() : bool|WP_Error
- Check batch limit.
- delete_post() : mixed
- Delete post.
- filter_writable_props() : bool
- Only return writable props from schema.
- get_allowed_query_vars() : array
- Get all the WP Query vars that are allowed for the API request.
- get_formatted_item_data() : array
- Get formatted item data.
- get_normalized_rest_base() : string
- Get normalized rest base.
- get_object() : WC_Data
- Get object.
- get_objects() : array
- Get objects.
- get_order_item_data() : array
- Expands an order item to get its data.
- get_order_statuses() : array
- Get order statuses without prefixes.
- get_permalink() : string
- Get object permalink.
- get_product_id() : int
- Gets the product ID from the SKU or posted ID.
- item_is_null() : bool
- Helper method to check if the resource ID associated with the provided item is null.
- maybe_set_item_meta_data() : mixed
- Maybe set item meta if posted.
- maybe_set_item_prop() : mixed
- Maybe set an item prop if the value was posted.
- maybe_set_item_props() : mixed
- Maybe set item props if the values were posted.
- prepare_coupon_lines() : WC_Order_Item_Coupon
- Create or update an order coupon.
- prepare_fee_lines() : WC_Order_Item_Fee
- Create or update an order fee.
- prepare_items_query() : array
- Determine the allowed query_vars for a get_items() response and prepare for WP_Query.
- prepare_line_items() : WC_Order_Item_Product
- Create or update a line item.
- prepare_links() : array
- Prepare links for the request.
- prepare_object_for_database() : WP_Error|WC_Data
- Prepares one object for create or update operation.
- prepare_objects_query() : array
- Prepare objects query.
- prepare_shipping_lines() : WC_Order_Item_Shipping
- Create or update an order shipping method.
- save_object() : WC_Data|WP_Error
- Save an object data.
- set_item() : mixed
- Wrapper method to create/update order items.
- update_address() : mixed
- Update address.
- update_post_meta_fields() : bool|WP_Error
- Update post meta fields.
- merge_meta_item_with_formatted_meta_display_attributes() : array
- Merge the `$formatted_meta_data` `display_key` and `display_value` attribute values into the corresponding {@link WC_Meta_Data}. Returns the merged array.
Properties
$hierarchical
If object is hierarchical.
protected
bool
$hierarchical
= alse
$namespace
Endpoint namespace.
protected
string
$namespace
= 'wc/v2'
$post_type
Post type.
protected
string
$post_type
= 'shop_order_refund'
$public
Controls visibility on frontend.
protected
string
$public
= alse
$request
Stores the request.
protected
array
$request
= array()
$rest_base
Route base.
protected
string
$rest_base
= 'orders/(?P<order_id>[\d]+)/refunds'
Methods
__construct()
Order refunds actions.
public
__construct() : mixed
Return values
mixedbatch_items()
Bulk create, update and delete items.
public
batch_items(WP_REST_Request $request) : array
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
array — Of WP_Error or WP_REST_Response.batch_items_permissions_check()
Check if a given request has access batch create, update and delete items.
public
batch_items_permissions_check(WP_REST_Request $request) : bool|WP_Error
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
bool|WP_Errorcreate_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_Responsecreate_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
-
Full details about the request.
Return values
WP_Error|booldelete_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_Errordelete_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
-
Full details about the request.
Return values
bool|WP_Errorget_collection_params()
Get the query params for collections.
public
get_collection_params() : array
Return values
arrayget_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([string $method = WP_REST_Server::CREATABLE ]) : array
Parameters
- $method : string = WP_REST_Server::CREATABLE
-
Optional. HTTP method of the request.
Return values
array — Endpoint arguments.get_fields_for_response()
Gets an array of fields to be included on the response.
public
get_fields_for_response(WP_REST_Request $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
Return values
array — Fields to be included in the response.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_Responseget_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
-
Full details about the request.
Return values
WP_Error|boolget_item_schema()
Get the Order's schema, conforming to JSON Schema.
public
get_item_schema() : array
Return values
arrayget_items()
Get a collection of posts.
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_Responseget_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|boolget_public_batch_schema()
Get the batch schema, conforming to JSON Schema.
public
get_public_batch_schema() : array
Return values
arrayprepare_object_for_response()
Prepare a single order output for response.
public
prepare_object_for_response(WC_Data $object, WP_REST_Request $request) : WP_Error|WP_REST_Response
Parameters
- $object : WC_Data
-
Object data.
- $request : WP_REST_Request
-
Request object.
Tags
Return values
WP_Error|WP_REST_Responseregister_routes()
Register the routes for order refunds.
public
register_routes() : mixed
Return values
mixedupdate_item()
Update a single post.
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_Responseupdate_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
-
Full details about the request.
Return values
WP_Error|boolvalidate_setting_checkbox_field()
Validate checkbox based settings.
public
validate_setting_checkbox_field(string $value, array $setting) : string|WP_Error
Parameters
- $value : string
-
Value.
- $setting : array
-
Setting.
Tags
Return values
string|WP_Errorvalidate_setting_image_width_field()
Validate image_width based settings.
public
validate_setting_image_width_field(array $values, array $setting) : string|WP_Error
Parameters
- $values : array
-
Values.
- $setting : array
-
Setting.
Tags
Return values
string|WP_Errorvalidate_setting_multiselect_field()
Validate multiselect based settings.
public
validate_setting_multiselect_field(array $values, array $setting) : array|WP_Error
Parameters
- $values : array
-
Values.
- $setting : array
-
Setting.
Tags
Return values
array|WP_Errorvalidate_setting_radio_field()
Validate radio based settings.
public
validate_setting_radio_field(string $value, array $setting) : string|WP_Error
Parameters
- $value : string
-
Value.
- $setting : array
-
Setting.
Tags
Return values
string|WP_Errorvalidate_setting_select_field()
Validate select based settings.
public
validate_setting_select_field(string $value, array $setting) : string|WP_Error
Parameters
- $value : string
-
Value.
- $setting : array
-
Setting.
Tags
Return values
string|WP_Errorvalidate_setting_text_field()
Validate a text value for a text based setting.
public
validate_setting_text_field(string $value, array $setting) : string
Parameters
- $value : string
-
Value.
- $setting : array
-
Setting.
Tags
Return values
stringvalidate_setting_textarea_field()
Validate textarea based settings.
public
validate_setting_textarea_field(string $value, array $setting) : string
Parameters
- $value : string
-
Value.
- $setting : array
-
Setting.
Tags
Return values
stringadd_additional_fields_schema()
Add the schema from additional fields to an schema array.
protected
add_additional_fields_schema(array $schema) : array
The type of object is inferred from the passed schema.
Parameters
- $schema : array
-
Schema array.
Return values
arrayadd_meta_query()
Add meta query.
protected
add_meta_query(array $args, array $meta_query) : array
Parameters
- $args : array
-
Query args.
- $meta_query : array
-
Meta query.
Tags
Return values
arrayadd_post_meta_fields()
Add post meta fields.
protected
add_post_meta_fields(WP_Post $post, WP_REST_Request $request) : bool|WP_Error
Parameters
- $post : WP_Post
-
Post Object.
- $request : WP_REST_Request
-
WP_REST_Request Object.
Return values
bool|WP_Erroradjust_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(array $endpoint_args) : 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.check_batch_limit()
Check batch limit.
protected
check_batch_limit(array $items) : bool|WP_Error
Parameters
- $items : array
-
Request items.
Return values
bool|WP_Errordelete_post()
Delete post.
protected
delete_post(WP_Post $post) : mixed
Parameters
- $post : WP_Post
-
Post object.
Return values
mixedfilter_writable_props()
Only return writable props from schema.
protected
filter_writable_props(array $schema) : bool
Parameters
- $schema : array
-
Schema.
Return values
boolget_allowed_query_vars()
Get all the WP Query vars that are allowed for the API request.
protected
get_allowed_query_vars() : array
Return values
arrayget_formatted_item_data()
Get formatted item data.
protected
get_formatted_item_data(WC_Data $object) : array
Parameters
- $object : WC_Data
-
WC_Data instance.
Tags
Return values
arrayget_normalized_rest_base()
Get normalized rest base.
protected
get_normalized_rest_base() : string
Return values
stringget_object()
Get object.
protected
get_object(int $id) : WC_Data
Parameters
- $id : int
-
Object ID.
Tags
Return values
WC_Dataget_objects()
Get objects.
protected
get_objects(array $query_args) : array
Parameters
- $query_args : array
-
Query args.
Tags
Return values
arrayget_order_item_data()
Expands an order item to get its data.
protected
get_order_item_data(WC_Order_item $item) : array
Parameters
- $item : WC_Order_item
-
Order item data.
Return values
arrayget_order_statuses()
Get order statuses without prefixes.
protected
get_order_statuses() : array
Return values
arrayget_permalink()
Get object permalink.
protected
get_permalink(object $object) : string
Parameters
- $object : object
-
Object.
Return values
stringget_product_id()
Gets the product ID from the SKU or posted ID.
protected
get_product_id(array $posted[, string $action = 'create' ]) : int
Parameters
- $posted : array
-
Request data.
- $action : string = 'create'
-
'create' to add line item or 'update' to update it.
Tags
Return values
intitem_is_null()
Helper method to check if the resource ID associated with the provided item is null.
protected
item_is_null(array $item) : 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.maybe_set_item_meta_data()
Maybe set item meta if posted.
protected
maybe_set_item_meta_data(WC_Order_Item $item, array $posted) : mixed
Parameters
- $item : WC_Order_Item
-
Order item data.
- $posted : array
-
Request data.
Return values
mixedmaybe_set_item_prop()
Maybe set an item prop if the value was posted.
protected
maybe_set_item_prop(WC_Order_Item $item, string $prop, array $posted) : mixed
Parameters
- $item : WC_Order_Item
-
Order item.
- $prop : string
-
Order property.
- $posted : array
-
Request data.
Return values
mixedmaybe_set_item_props()
Maybe set item props if the values were posted.
protected
maybe_set_item_props(WC_Order_Item $item, string[] $props, array $posted) : mixed
Parameters
- $item : WC_Order_Item
-
Order item data.
- $props : string[]
-
Properties.
- $posted : array
-
Request data.
Return values
mixedprepare_coupon_lines()
Create or update an order coupon.
protected
prepare_coupon_lines(array $posted[, string $action = 'create' ][, object $item = 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
Return values
WC_Order_Item_Couponprepare_fee_lines()
Create or update an order fee.
protected
prepare_fee_lines(array $posted[, string $action = 'create' ][, object $item = 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
Return values
WC_Order_Item_Feeprepare_items_query()
Determine the allowed query_vars for a get_items() response and prepare for WP_Query.
protected
prepare_items_query([array $prepared_args = array() ][, WP_REST_Request $request = null ]) : array
Parameters
- $prepared_args : array = array()
-
Prepared arguments.
- $request : WP_REST_Request = null
-
Request object.
Return values
array — $query_argsprepare_line_items()
Create or update a line item.
protected
prepare_line_items(array $posted[, string $action = 'create' ][, object $item = 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
Return values
WC_Order_Item_Productprepare_links()
Prepare links for the request.
protected
prepare_links(WC_Data $object, WP_REST_Request $request) : array
Parameters
- $object : WC_Data
-
Object data.
- $request : WP_REST_Request
-
Request object.
Return values
array — Links for the given post.prepare_object_for_database()
Prepares one object for create or update operation.
protected
prepare_object_for_database(WP_REST_Request $request[, bool $creating = false ]) : WP_Error|WC_Data
Parameters
- $request : WP_REST_Request
-
Request object.
- $creating : bool = false
-
If is creating a new object.
Tags
Return values
WP_Error|WC_Data — The prepared item, or WP_Error object on failure.prepare_objects_query()
Prepare objects query.
protected
prepare_objects_query(WP_REST_Request $request) : array
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Tags
Return values
arrayprepare_shipping_lines()
Create or update an order shipping method.
protected
prepare_shipping_lines(array $posted[, string $action = 'create' ][, object $item = 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
Return values
WC_Order_Item_Shippingsave_object()
Save an object data.
protected
save_object(WP_REST_Request $request[, bool $creating = 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
Return values
WC_Data|WP_Errorset_item()
Wrapper method to create/update order items.
protected
set_item(WC_Order $order, string $item_type, array $posted) : 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
Return values
mixedupdate_address()
Update address.
protected
update_address(WC_Order $order, array $posted[, string $type = 'billing' ]) : mixed
Parameters
- $order : WC_Order
-
Order data.
- $posted : array
-
Posted data.
- $type : string = 'billing'
-
Address type.
Return values
mixedupdate_post_meta_fields()
Update post meta fields.
protected
update_post_meta_fields(WP_Post $post, WP_REST_Request $request) : bool|WP_Error
Parameters
- $post : WP_Post
-
Post object.
- $request : WP_REST_Request
-
Request object.
Return values
bool|WP_Errormerge_meta_item_with_formatted_meta_display_attributes()
Merge the `$formatted_meta_data` `display_key` and `display_value` attribute values into the corresponding {@link WC_Meta_Data}. Returns the merged array.
private
merge_meta_item_with_formatted_meta_display_attributes(WC_Meta_Data $meta_item, array $formatted_meta_data) : array
Parameters
- $meta_item : WC_Meta_Data
-
An object from {@link WC_Order_Item::get_meta_data()}.
- $formatted_meta_data : array
-
An object result from {@link WC_Order_Item::get_formatted_meta_data}. The keys are the IDs of {@link WC_Meta_Data}.