WC_REST_Products_V4_Controller::get_collection_params │ public │ WC 1.0
Add new options for 'orderby' to the collection params.
Method of the class: WC_REST_Products_V4_Controller{}
No Hooks.
Returns
Array.
Usage
$WC_REST_Products_V4_Controller = new WC_REST_Products_V4_Controller(); $WC_REST_Products_V4_Controller->get_collection_params();
WC_REST_Products_V4_Controller::get_collection_params() WC REST Products V4 Controller::get collection params code WC 10.3.6
woocommerce/includes/rest-api/Controllers/Version4/Products/class-wc-rest-products-v4-controller.php
public function get_collection_params() {
$params = parent::get_collection_params();
$params['orderby']['enum'] = array_merge( $params['orderby']['enum'], array( 'price', 'popularity', 'rating' ) );
unset( $params['in_stock'] );
$params['stock_status'] = array(
'description' => __( 'Limit result set to products with specified stock status.', 'woocommerce' ),
'type' => 'string',
'enum' => array_keys( wc_get_product_stock_status_options() ),
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => 'rest_validate_request_arg',
);
$params['search_sku'] = array(
'description' => __( "Limit results to those with a SKU that partial matches a string. This argument takes precedence over 'sku'.", 'woocommerce' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => 'rest_validate_request_arg',
);
$params['search_name_or_sku'] = array(
'description' => __( "Limit results to those with a name or SKU that partial matches a string. This argument takes precedence over 'search', 'sku' and 'search_sku'.", 'woocommerce' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => 'rest_validate_request_arg',
);
$search_fields_enum = array( 'name', 'global_unique_id', 'description', 'short_description' );
if ( wc_product_sku_enabled() ) {
$search_fields_enum[] = 'sku';
}
$params['search_fields'] = array(
'description' => __( 'Limit search to specific fields when used with search parameter. Available fields: name, sku, global_unique_id, description, short_description. This argument takes precedence over all other search parameters.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'string',
'enum' => $search_fields_enum,
),
'default' => array(),
'sanitize_callback' => 'wp_parse_slug_list',
'validate_callback' => 'rest_validate_request_arg',
);
$params['include_status'] = array(
'description' => __( 'Limit result set to products with any of the statuses.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'string',
'enum' => array_merge( array( 'any', ProductStatus::FUTURE, ProductStatus::TRASH ), array_keys( get_post_statuses() ) ),
),
'sanitize_callback' => 'wp_parse_list',
'validate_callback' => 'rest_validate_request_arg',
);
$params['exclude_status'] = array(
'description' => __( 'Exclude products with any of the statuses from result set.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'string',
'enum' => array_merge( array( ProductStatus::FUTURE, ProductStatus::TRASH ), array_keys( get_post_statuses() ) ),
),
'sanitize_callback' => 'wp_parse_list',
'validate_callback' => 'rest_validate_request_arg',
);
$params['include_types'] = array(
'description' => __( 'Limit result set to products with any of the types.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'string',
'enum' => array_keys( wc_get_product_types() ),
),
'sanitize_callback' => 'wp_parse_list',
'validate_callback' => 'rest_validate_request_arg',
);
$params['exclude_types'] = array(
'description' => __( 'Exclude products with any of the types from result set.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'string',
'enum' => array_keys( wc_get_product_types() ),
),
'sanitize_callback' => 'wp_parse_list',
'validate_callback' => 'rest_validate_request_arg',
);
$params['downloadable'] = array(
'description' => __( 'Limit result set to downloadable products.', 'woocommerce' ),
'type' => 'boolean',
'sanitize_callback' => 'rest_sanitize_boolean',
'validate_callback' => 'rest_validate_request_arg',
);
$params['virtual'] = array(
'description' => __( 'Limit result set to virtual products.', 'woocommerce' ),
'type' => 'boolean',
'sanitize_callback' => 'rest_sanitize_boolean',
'validate_callback' => 'rest_validate_request_arg',
);
return $params;
}