Skip to content

Instantly share code, notes, and snippets.

@dislokacia
Created July 7, 2022 21:05
Show Gist options
  • Save dislokacia/8269c6710f78bd2103f7f8302461ddd7 to your computer and use it in GitHub Desktop.
Save dislokacia/8269c6710f78bd2103f7f8302461ddd7 to your computer and use it in GitHub Desktop.
JetSearch with empty input and checked category
jQuery(document).ready(function( $ ){
$('.jet-ajax-search__submit').on('click',function(){
$('.jet-ajax-search__form').submit();
})
$(".jet-ajax-search__submit").on('keyup', function (e) {
if (e.key === 'Enter' || e.keyCode === 13) {
$('.jet-ajax-search__form').submit();
}
});
});
@dislokacia
Copy link
Author

This code will allow you to search through the search button or 'enter' keypress when your search input will be empty
If you want, to get the results filtered by one of this categories https://prnt.sc/G43Ptecv3N1Q , you should create the Custom Query
In my example I want to query with the Product Categories https://prnt.sc/2DdZrQkBbjfB
As I search through the Products, I create the WC Query https://prnt.sc/dv0jZekhmWhL and the main point is create the Tax Query https://prnt.sc/VPSsynjmTzIv with Query Variable https://prnt.sc/4loxTSdQy4Wk jet_ajax_search_categories
It worked for me as I needed https://www.loom.com/share/08d8b9f1beec4be9aef8dfef6b510f26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment