PHP Class WC_REST_Products_Controller

Inheritance: extends WC_REST_Posts_Controller
Show file Open project: woocommerce/woocommerce Class Usage Examples

Protected Properties

Property Type Description
$namespace string Endpoint namespace.
$post_type string Post type.
$rest_base string Route base.

Public Methods

Method Description
__construct ( ) Initialize product actions.
clear_transients ( WP_Post $post ) Clear cache/transients.
create_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response Create a single product.
delete_item ( WP_REST_Request $request ) : WP_REST_Response | WP_Error Delete a single item.
get_collection_params ( ) : array Get the query params for collections of attachments.
get_item_schema ( ) : array Get the Product's schema, conforming to JSON Schema.
prepare_item_for_response ( WP_Post $post, WP_REST_Request $request ) : WP_REST_Response Prepare a single product output for response.
query_args ( array $args, WP_REST_Request $request ) : array Query args.
register_routes ( ) Register the routes for products.
save_product ( WP_REST_Request $request ) : integer Saves a product to the database.
update_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response Update a single product.

Protected Methods

Method Description
add_post_meta_fields ( WP_Post $post, WP_REST_Request $request ) : boolean | WP_Error Add post meta fields.
delete_post ( integer | WP_Post $id ) Delete post.
get_attribute_options ( integer $product_id, array $attribute ) : array Get attribute options.
get_attribute_taxonomy_label ( string $name ) : string Get attribute taxonomy label.
get_attributes ( WC_Product | WC_Product_Variation $product ) : array Get the attributes for a product or product variation.
get_default_attributes ( WC_Product $product ) : array Get default attributes.
get_downloads ( WC_Product | WC_Product_Variation $product ) : array Get the downloads for a product or product variation.
get_images ( WC_Product | WC_Product_Variation $product ) : array Get the images for a product or product variation.
get_product_data ( WC_Product $product ) : array Get product data.
get_taxonomy_terms ( WC_Product $product, string $taxonomy = 'cat' ) : array Get taxonomy terms.
get_variation_data ( WC_Product $product ) : array Get an individual variation's data.
prepare_item_for_database ( WP_REST_Request $request ) : WP_Error | stdClass Prepare a single product for create or update.
prepare_links ( WC_Product $product, WP_REST_Request $request ) : array Prepare links for the request.
save_default_attributes ( WC_Product $product, WP_REST_Request $request ) : WC_Product Save default attributes.
save_product_images ( WC_Product $product, array $images ) : WC_Product Save product images.
save_product_meta ( WC_Product $product, WP_REST_Request $request ) : WC_Product Save product meta.
save_taxonomy_terms ( WC_Product $product, array $terms, string $taxonomy = 'cat' ) : WC_Product Save taxonomy terms.
save_variations_data ( WC_Product $product, WP_REST_Request $request, boolean $single_variation = false ) : boolean Save variations.
update_post_meta_fields ( WP_Post $post, WP_REST_Request $request ) : boolean | WP_Error Update post meta fields.

Private Methods

Method Description
save_downloadable_files ( WC_Product $product, array $downloads, integer $deprecated ) : WC_Product Save downloadable files.
save_product_shipping_data ( WC_Product $product, array $data ) : WC_Product Save product shipping data.

Method Details

__construct() public method

Initialize product actions.
public __construct ( )

add_post_meta_fields() protected method

Add post meta fields.
protected add_post_meta_fields ( WP_Post $post, WP_REST_Request $request ) : boolean | WP_Error
$post WP_Post Post data.
$request WP_REST_Request Request data.
return boolean | WP_Error

clear_transients() public method

Clear cache/transients.
public clear_transients ( WP_Post $post )
$post WP_Post Post data.

create_item() public method

Create a single product.
public create_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response
$request WP_REST_Request Full details about the request.
return WP_Error | WP_REST_Response

delete_item() public method

Delete a single item.
public delete_item ( WP_REST_Request $request ) : WP_REST_Response | WP_Error
$request WP_REST_Request Full details about the request.
return WP_REST_Response | WP_Error

delete_post() protected method

Delete post.
protected delete_post ( integer | WP_Post $id )
$id integer | WP_Post Post ID or WP_Post instance.

get_attribute_options() protected method

Get attribute options.
protected get_attribute_options ( integer $product_id, array $attribute ) : array
$product_id integer Product ID.
$attribute array Attribute data.
return array

get_attribute_taxonomy_label() protected method

Get attribute taxonomy label.
protected get_attribute_taxonomy_label ( string $name ) : string
$name string Taxonomy name.
return string

get_attributes() protected method

Get the attributes for a product or product variation.
protected get_attributes ( WC_Product | WC_Product_Variation $product ) : array
$product WC_Product | WC_Product_Variation Product instance.
return array

get_collection_params() public method

Get the query params for collections of attachments.
public get_collection_params ( ) : array
return array

get_default_attributes() protected method

Get default attributes.
protected get_default_attributes ( WC_Product $product ) : array
$product WC_Product Product instance.
return array

get_downloads() protected method

Get the downloads for a product or product variation.
protected get_downloads ( WC_Product | WC_Product_Variation $product ) : array
$product WC_Product | WC_Product_Variation Product instance.
return array

get_images() protected method

Get the images for a product or product variation.
protected get_images ( WC_Product | WC_Product_Variation $product ) : array
$product WC_Product | WC_Product_Variation Product instance.
return array

get_item_schema() public method

Get the Product's schema, conforming to JSON Schema.
public get_item_schema ( ) : array
return array

get_product_data() protected method

Get product data.
protected get_product_data ( WC_Product $product ) : array
$product WC_Product Product instance.
return array

get_taxonomy_terms() protected method

Get taxonomy terms.
protected get_taxonomy_terms ( WC_Product $product, string $taxonomy = 'cat' ) : array
$product WC_Product Product instance.
$taxonomy string Taxonomy slug.
return array

get_variation_data() protected method

Get an individual variation's data.
protected get_variation_data ( WC_Product $product ) : array
$product WC_Product Product instance.
return array

prepare_item_for_database() protected method

Prepare a single product for create or update.
protected prepare_item_for_database ( WP_REST_Request $request ) : WP_Error | stdClass
$request WP_REST_Request Request object.
return WP_Error | stdClass $data Post object.

prepare_item_for_response() public method

Prepare a single product output for response.
public prepare_item_for_response ( WP_Post $post, WP_REST_Request $request ) : WP_REST_Response
$post WP_Post Post object.
$request WP_REST_Request Request object.
return WP_REST_Response

query_args() public method

Query args.
public query_args ( array $args, WP_REST_Request $request ) : array
$args array Request args.
$request WP_REST_Request Request data.
return array

register_routes() public method

Register the routes for products.
public register_routes ( )

save_default_attributes() protected method

Save default attributes.
Since: 2.7.0
protected save_default_attributes ( WC_Product $product, WP_REST_Request $request ) : WC_Product
$product WC_Product Product instance.
$request WP_REST_Request Request data.
return WC_Product

save_product() public method

Saves a product to the database.
public save_product ( WP_REST_Request $request ) : integer
$request WP_REST_Request Full details about the request.
return integer

save_product_images() protected method

Save product images.
protected save_product_images ( WC_Product $product, array $images ) : WC_Product
$product WC_Product Product instance.
$images array Images data.
return WC_Product

save_product_meta() protected method

Save product meta.
protected save_product_meta ( WC_Product $product, WP_REST_Request $request ) : WC_Product
$product WC_Product Product instance.
$request WP_REST_Request Request data.
return WC_Product

save_taxonomy_terms() protected method

Save taxonomy terms.
protected save_taxonomy_terms ( WC_Product $product, array $terms, string $taxonomy = 'cat' ) : WC_Product
$product WC_Product Product instance.
$terms array Terms data.
$taxonomy string Taxonomy name.
return WC_Product

save_variations_data() protected method

Save variations.
protected save_variations_data ( WC_Product $product, WP_REST_Request $request, boolean $single_variation = false ) : boolean
$product WC_Product Product instance.
$request WP_REST_Request Request data.
$single_variation boolean True if saving only a single variation.
return boolean

update_item() public method

Update a single product.
public update_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response
$request WP_REST_Request Full details about the request.
return WP_Error | WP_REST_Response

update_post_meta_fields() protected method

Update post meta fields.
protected update_post_meta_fields ( WP_Post $post, WP_REST_Request $request ) : boolean | WP_Error
$post WP_Post Post data.
$request WP_REST_Request Request data.
return boolean | WP_Error

Property Details

$namespace protected property

Endpoint namespace.
protected string $namespace
return string

$post_type protected property

Post type.
protected string $post_type
return string

$rest_base protected property

Route base.
protected string $rest_base
return string