Guest User

Auto Append Search Query To Only Include Products <script> jQuery(document).ready(function($) {

a guest
Nov 14th, 2025
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. <script>
  2. jQuery(document).ready(function($) {
  3. // Attach event handler to the search form submission
  4. $('form.e-search-form').on('submit', function(event) {
  5. // Prevent the default form submission
  6. event.preventDefault();
  7.  
  8. // Get the search input value
  9. var searchQuery = $(this).find('input[type="search"]').val();
  10.  
  11. // Redirect to the search results page with the product post type query
  12. var searchUrl = '/?s=' + searchQuery + '&post_type=product';
  13. window.location.href = searchUrl;
  14. });
  15. });
  16. </script>
Advertisement
Add Comment
Please, Sign In to add comment