WooCommerce Code Reference

WC_REST_Products_V2_Controller extends WC_REST_CRUD_Controller

REST API Products controller class.

Tags
extends

WC_REST_CRUD_Controller

Table of Contents

$hierarchical  : bool
If object is hierarchical.
$namespace  : string
Endpoint namespace.
$post_type  : string
Post type.
$public  : string
Controls visibility on frontend.
$rest_base  : string
Route base.
__construct()  : mixed
Initialize product 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.
clear_transients()  : mixed
Clear caches here so in sync with any new variations/children.
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 of attachments.
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 Product'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_REST_Response
Prepare a single product output for response.
register_routes()  : mixed
Register the routes for products.
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.
get_allowed_query_vars()  : array
Get all the WP Query vars that are allowed for the API request.
get_attribute_options()  : array
Get attribute options.
get_attribute_taxonomy_label()  : string
Get attribute taxonomy label.
get_attribute_taxonomy_name()  : string
Get product attribute taxonomy name.
get_attributes()  : array
Get the attributes for a product or product variation.
get_default_attributes()  : array
Get default attributes.
get_downloads()  : array
Get the downloads for a product or product variation.
get_images()  : array
Get the images for a product or product variation.
get_normalized_rest_base()  : string
Get normalized rest base.
get_object()  : WC_Data
Get object.
get_objects()  : array
Get objects.
get_permalink()  : string
Get object permalink.
get_product_data()  : array
Get product data.
get_taxonomy_terms()  : array
Get taxonomy terms.
prepare_items_query()  : array
Determine the allowed query_vars for a get_items() response and prepare for WP_Query.
prepare_links()  : array
Prepare links for the request.
prepare_object_for_database()  : WP_Error|WC_Data
Prepare a single product for create or update.
prepare_objects_query()  : array
Prepare objects query.
save_default_attributes()  : WC_Product
Save default attributes.
save_downloadable_files()  : WC_Product
Save downloadable files.
save_object()  : WC_Data|WP_Error
Save an object data.
save_product_shipping_data()  : WC_Product
Save product shipping data.
save_taxonomy_terms()  : WC_Product
Save taxonomy terms.
set_product_images()  : WC_Product
Set product images.
update_post_meta_fields()  : bool|WP_Error
Update post meta fields.

Properties

Methods

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_Error

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
since
3.5.0
Return values
arrayFields to be included in the response.

validate_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
since
3.0.0
Return values
string|WP_Error

validate_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
since
3.0.0
Return values
string|WP_Error

validate_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
since
3.0.0
Return values
array|WP_Error

add_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
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.

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
mixedSchema with converted datatype.

prepare_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_args