Tagged: ajax search, product search, woocommerce
-
AuthorPosts
-
October 16, 2017 at 2:42 pm #864826
Hi,
Is it possible to change the search results to show product search results instead?
Thanks
October 17, 2017 at 5:45 am #865122Hey mrb1972,
I’m not sure I understand what you mean, do you want searches to only return product results?
Best regards,
RikardOctober 17, 2017 at 11:53 am #865244Sorry let me try and explain better, I would like the main search function to work in the same way as the “Product Search” widget does, so it only shows products (nothing else) in the gird shop layout!
I have used Relevanssi to only show products but I want the results to show the same way as the “product search” widget does
Hope that makes sense
October 18, 2017 at 5:24 pm #865842Hi mrb1972,
So why not use the Product Search plugin all the way, if it already does what you need?
Best regards,
VictoriaOctober 18, 2017 at 5:27 pm #865845Because it shows the results as a text list rather than a product list in the shop
- This reply was modified 7 years, 2 months ago by mrb1972.
October 20, 2017 at 4:48 am #866554Hi,
You can’t set the ajax search to return the product search results but you can replace it with the product search widget. Disable the default search icon and then add the following filter in the functions.php file.
add_filter( 'wp_nav_menu_items', 'woocommerce_product_search_mod', 9997, 2 ); function woocommerce_product_search_mod( $items, $args ) { ob_start(); ?> <form role="search" method="get" class="woocommerce-product-search" action="<?php echo esc_url( home_url( '/' ) ); ?>"> <label class="screen-reader-text" for="woocommerce-product-search-field-<?php echo isset( $index ) ? absint( $index ) : 0; ?>"><?php _e( 'Search for:', 'woocommerce' ); ?></label> <input type="search" id="woocommerce-product-search-field-<?php echo isset( $index ) ? absint( $index ) : 0; ?>" class="search-field" placeholder="<?php echo esc_attr__( 'Search products…', 'woocommerce' ); ?>" value="<?php echo get_search_query(); ?>" name="s" /> <input type="submit" value="<?php echo esc_attr_x( 'Search', 'submit button', 'woocommerce' ); ?>" /> <input type="hidden" name="post_type" value="product" /> </form> <?php $form = ob_get_clean(); $items .= '<li id="menu-item-search" class="noMobile menu-item menu-item-search-dropdown menu-item-avia-special">'.$form.'</li>'; return $items; }
It may require a few css adjustments.
Best regards,
IsmaelOctober 23, 2017 at 11:22 am #867558Thanks, that didn’t work quite how I wanted but I did manage to create a new searchform.php file in the child theme and change the form code to this
<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>
I works with Relevanssi but i’m not sure if code is technically correct , im not a coder, but it seems to work..
- This reply was modified 7 years, 2 months ago by mrb1972.
October 23, 2017 at 12:01 pm #867584Hi mrb1972,
Glad you got it working for you! :)
If you need further assistance please let us know.
Best regards,
VictoriaOctober 26, 2017 at 2:12 pm #869193Thank you for sharing! this helped me! I am not using the Relvanssi plugin, but it replaces the ajax search in the menu with the product search
October 26, 2017 at 2:14 pm #869195No problem, im not really a coder as such so got it working buy trial and error,, it seems to work so I guess the code is ok :)
October 26, 2017 at 2:27 pm #869203Ideally, it would be great if the product search results display first, and other search results from pages and posts display after…
I noticed that this code replaces the search for pages and posts of the normal search widget.October 26, 2017 at 2:28 pm #869204yes, that was what I wanted, just the products showing, nothing else
- This reply was modified 7 years, 1 month ago by mrb1972.
October 29, 2017 at 5:35 pm #870134 -
AuthorPosts
- You must be logged in to reply to this topic.