-
AuthorPosts
-
August 29, 2019 at 6:32 pm #1132043
Hi Guys,
The built in search function in Enfold isn’t sophisticated enough for Woocommerce Search Results.Question 1:
Is there a way within enfold to restore the default Woo Commerce Search Function? This would search products only like on the https://themes.woocommerce.com/storefront/ demo.Question 2:
The Ajax search works excellently with the shop. Is there a way to disable the search results page. So users only see the Ajax search results? Pressing enter should do nothing and the clicking the magnifying glass next to the search box should do nothing.Hope you can help!
August 29, 2019 at 8:16 pm #1132070Hey Thomas,
Please have a look at the solution posted here
Best regards,
VictoriaAugust 30, 2019 at 11:10 am #1132277I’ll give that a try and reply here if it does what I need it to do.
September 1, 2019 at 12:50 pm #1132663Hi,
Thanks for the update, please let us know if you should need any further help on the topic.
Best regards,
RikardSeptember 2, 2019 at 4:00 pm #1133044As Promised, the solution below changes the default search form to make it:
-Show products in a grid
-Add SKUs to the standard search
-Fixes the Ajax search so it all matchesReplace the search form
Edit the searchform.php (use your child theme to make a copy) Replace the default form with the following:<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>"> <div> <input type="text" id="s" name="s" value="<?php if(!empty($_GET['s'])) echo get_search_query(); ?>" placeholder='<?php echo $search_params['placeholder']; ?>'> <input type="submit" value="<?php echo $icon; ?>" id="searchsubmit" class="button <?php echo $class; ?>" /> <input type="hidden" name="post_type" value="product"> </div> </form>
Add SKUs to the default search
The guy who put this together is brilliant thank you! Add the following to your child theme’s functions.php file:/** __________________________________ ENHANCE THE STANDARD SEARCH * Join posts and postmeta tables * This one hels to include the SKU in tzhe standard search * http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join */ function cf_search_join( $join ) { global $wpdb; if ( is_search() || !empty($_REQUEST['s'] )) { $join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id '; } return $join; } add_filter('posts_join', 'cf_search_join' ); /** * Modify the search query with posts_where * * http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_where */ function cf_search_where( $where ) { global $pagenow, $wpdb; if ( is_search() || !empty($_REQUEST['s'] ) ) { $where = preg_replace( "/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/", "(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where ); } return $where; } add_filter( 'posts_where', 'cf_search_where' ); /** * Prevent duplicates * * http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_distinct */ function cf_search_distinct( $where ) { global $wpdb; if ( is_search() || !empty($_REQUEST['s'] ) ) { return "DISTINCT"; } return $where; } add_filter( 'posts_distinct', 'cf_search_distinct' ); /* END Search includes SKU */
Hope this helps other people. It makes the Search in Enfold do what it should when Woocommerce is installed.
September 3, 2019 at 8:13 am #1133257Hi,
Great, thanks for sharing your solution. It’s much appreciated :-)
Best regards,
RikardSeptember 20, 2019 at 10:03 am #1140159this solution is really good and works like a charm! thank you for sharing!
September 20, 2019 at 10:23 am #1140162Glad this helped Lars! I pieced this together from other forum entries so I cannot take credit for the code but the solution seems to do what most people (including myself) were looking for!
September 20, 2019 at 5:47 pm #1140273Hi,
Did you need additional help or shall we close this topic?
Best regards,
Jordan ShannonOctober 2, 2019 at 12:19 pm #1144139Hi Jordan,
Please close the topic. The solution above seems to work fine.
October 2, 2019 at 4:40 pm #1144199Hi,
I’m glad this was resolved. If you need additional help, please let us know here in the forums.
Best regards,
Jordan Shannon -
AuthorPosts
- The topic ‘Improved search for Woo Commerce’ is closed to new replies.