0

I have been struggling with this and could not find a clear answer online.

Will putting a product search bar I have a dropdown visible with all the categories you can search in. I would just like to keep only the categories and remove the "all categories" option.

You can see the current search I would like to fix here : https://compare-tech.fr

Thank you to anyone who will be able to help :)

2
  • Welcome Antoine! Please answer a question or two, so we might provide more accurate recommendations. 1. Did you code this search, or are you using a default Wordpress widget? 2. If you coded this, would you please provide a sample of your code, so we can advise you how to modify it. – Mike Baxter Jan 6 '20 at 17:53
  • Hello, Thank you for your answer. This is the default wordpress widget. – Antoine Jan 6 '20 at 18:23
0

This list can be modified using WooCommerce filters. However, without a thorough testing I could not find a specific filter to help you. You might check the API for a better answer.

Meanwhile, I have used this CSS snippet to successfully hide the "All Categories" entry from the drop-down selector:

li.option[data-value=''] {
    display: none;
}

This will only prevent users from selecting "All Categories" again. It will not prevent your page from defaulting to "All Categories".

Hope this is helpful!

1
  • Thank you for your help ! We are halfway there. The "All categories" only shows before anything else is selected. So I just need to change the default selected category. I used this : function wp_dropdown_categories( $args = '' ) { $defaults = array( 'selected' => 2, ); But it crashed my website.. that might not be it. Can anyone see my mistake ? – Antoine Jan 8 '20 at 15:00
0

Thank you for your help !

We are halfway there. The "All categories" only shows before anything else is selected. So I just need to change the default selected category.

I used this :

function wp_dropdown_categories( $args = '' ) { $defaults = array( 'selected' => 2, ); 

But it crashed my website.. that might not be it. Can anyone see my mistake ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.