• Resolved shadowq

    (@shadowq)


    Hi there,

    I know that you can exclude categories from some of the filters, such as the categories filter. However, is it possible to exclude certain products or categories from the search autocomplete? Or is there a list of hooks (actions/filters) that I could plug in to?

    TIA

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author annastaa

    (@annastaa)

    Hello Shadowq,

    I suppose it would take a bit of an effort, but could probably be accomplished. First of all, here is the way to “catch” the autocomplete calls:

    if( wp_doing_ajax() && isset( $_REQUEST['awf_front'] ) && isset( $_GET['awf_action'] ) && 'get_search_autocomplete' === $_GET['awf_action'] ) {
    
      // autocomplete-related code here
    
    }

    The autocomplete queries use the same WooCommerce string search engine as the rest of the keywords search. You can hook into it using the woocommerce_product_pre_search_products hook to alter the keywords query, or simply parse the WP query using the pre_get_posts or any other convenient hook, which would probably make sense in case you need to filter out some product categories or other taxonomies.

    And finally, I assume that you have already seen it and it’s not exactly what you need, but enabling the Apply filters to autocomplete results option will apply all the currently active filters to autocomplete returns. You will find the active filters in the $_GET[‘awf_query’] (requested from inside of the conditional statement that I give above).

    Plugin Author annastaa

    (@annastaa)

    Hello @shadowq,

    We’ll close this inactive thread, please open a new one if you have any further questions about our WooCommerce filters!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exclude categories from search’ is closed to new replies.