Is there a way - through the functions.php or other - to add custom filters to Woocommerce's wp-json/wc/v3/products endpoint?
First off, i'm aware you can add parameters to this URL , however this exact path is accessed by an external tool we use so I have no way to change the URL itself.
I would like to tell WooCommerce that if this exact URL is accessed, some products should not be sent.
Adding additional filters like /categories to the URL sadly is not an option, it needs to be wp-json/wc/v3/products exactly.
Here's what i tried to exclude the product with ID 10522, but it doesn't quite seem to work:
function maximum_api_filter($query_params) {
$query_params['exclude'][10522];
return $query_params;
}
add_filter('rest_product_collection_params', 'maximum_api_filter');
It seems like the following code did what i wanted.
It filtered out any products that are priced at 0.00, so anything that costs 0.01 or more is included:
function maximum_api_filter($query_params) {
$query_params =array("min_price", "0.01");
return $query_params;
}
add_filter('rest_product_collection_params', 'maximum_api_filter');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.