Make the default Divi search box search WooCommerce products only

Divi Tips, WooCommerce Tips

If you have a Divi/WooCommerce site and you don’t have any posts, this is perfect for you. The default Divi search will now search only your products.

You can add this to the Divi theme options Integration tab in the head. Or add to a Code module in your global header.

This also changes the placeholder text from “Search” to “Search Products”. For example when you click on the search icon like below.
change-search-products

It will show this:
change-search-products2

Make sure you put the code inside a script tag.

jQuery(document).ready(function($){ // wait for jQuery to load
  $(".et-search-form").append(''); // dynamically add the input below the search box that tells the search that the post type to search are products.
  $(".et_pb_menu__search-form").each(function() { // now for each search box from the Divi module
  $(this).append(''); // add that input there too
  });
});
// change placeholder text on default Divi search box
window.onload = function() {
let searchinput = document.getElementsByClassName('et_pb_menu__search-input')[0];
searchinput.placeholder = "Search Products";
}

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.