Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #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!

    #1132070

    Hey Thomas,

    Please have a look at the solution posted here

    Change Search results to products search results (Woocommerce)

    Best regards,
    Victoria

    #1132277

    I’ll give that a try and reply here if it does what I need it to do.

    #1132663

    Hi,

    Thanks for the update, please let us know if you should need any further help on the topic.

    Best regards,
    Rikard

    #1133044

    As 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 matches

    Replace 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.

    #1133257

    Hi,

    Great, thanks for sharing your solution. It’s much appreciated :-)

    Best regards,
    Rikard

    #1140159

    this solution is really good and works like a charm! thank you for sharing!

    #1140162

    Glad 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!

    #1140273

    Hi,

    Did you need additional help or shall we close this topic?

    Best regards,
    Jordan Shannon

    #1144139

    Hi Jordan,

    Please close the topic. The solution above seems to work fine.

    #1144199

    Hi,

    I’m glad this was resolved. If you need additional help, please let us know here in the forums.

    Best regards,
    Jordan Shannon

Viewing 11 posts - 1 through 11 (of 11 total)

The topic ‘Improved search for Woo Commerce’ is closed to new replies.