rest_(taxonomy)_collection_params │ filter-hook │ WC 11.3.0

Filter collection parameters for the terms controller.

The dynamic portion of the hook name, $this->taxonomy, refers to the taxonomy slug. Shares its name with the WordPress core hook, so a callback added for a taxonomy served by both /wp/v2 and /wc/v3 runs for both.

This filter only registers parameters; use woocommerce_rest_{$taxonomy}_query to map them to WP_Term_Query arguments.

Usage

add_filter( 'rest_(taxonomy)_collection_params', 'wp_kama_rest_taxonomy_collection_params_filter', 10, 2 );

/**
 * Function for `rest_(taxonomy)_collection_params` filter-hook.
 * 
 * @param array       $params   JSON Schema-formatted collection parameters.
 * @param WP_Taxonomy $taxonomy Taxonomy object.
 *
 * @return array
 */
function wp_kama_rest_taxonomy_collection_params_filter( $params, $taxonomy ){
	// filter...
	return $params;
}
$params(array)
JSON Schema-formatted collection parameters.
$taxonomy(WP_Taxonomy)
Taxonomy object.

Changelog

Since 11.3.0 Introduced.

Where the hook is called

WC_REST_Terms_Controller::get_collection_params()
rest_(taxonomy)_collection_params
woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-terms-controller.php 817
return apply_filters( "rest_{$this->taxonomy}_collection_params", $params, $taxonomy_obj );

Where the hook is used in WooCommerce

woocommerce/includes/class-wc-brands.php 72
add_filter( 'rest_product_collection_params', array( $this, 'rest_api_product_collection_params' ), 10, 2 );
woocommerce/src/Blocks/BlockTypes/ProductCollection/Controller.php 80
add_filter( 'rest_product_collection_params', array( $this, 'extend_rest_query_allowed_params' ), 10, 1 );
woocommerce/src/Blocks/BlockTypes/ProductQuery.php 92
add_filter( 'rest_product_collection_params', array( $this, 'extend_rest_query_allowed_params' ), 10, 1 );