• Resolved radicalm1nd

    (@radicalm1nd)


    This is gonna be a little more technical than a regular support requests, but I direly need help with this so here goes:
    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/endpoints 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 10522which 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');
    • This topic was modified 4 years, 11 months ago by radicalm1nd.
Viewing 1 replies (of 1 total)
  • Thread Starter radicalm1nd

    (@radicalm1nd)

    I seem to have solved this with the following code:

    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');
Viewing 1 replies (of 1 total)
  • The topic ‘Woocommerce REST API – filtering wp-json/wc/v3/products’ is closed to new replies.