Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #864826

    Hi,

    Is it possible to change the search results to show product search results instead?

    Thanks

    #865122

    Hey mrb1972,

    I’m not sure I understand what you mean, do you want searches to only return product results?

    Best regards,
    Rikard

    #865244

    Sorry 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

    #865842

    Hi mrb1972,

    So why not use the Product Search plugin all the way, if it already does what you need?

    Best regards,
    Victoria

    #865845

    Because 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.
    #866554

    Hi,

    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&hellip;', '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,
    Ismael

    #867558

    Thanks, 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.
    #867584

    Hi mrb1972,

    Glad you got it working for you! :)

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #869193

    Thank 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

    #869195

    No 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 :)

    #869203

    Ideally, 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.

    #869204

    yes, that was what I wanted, just the products showing, nothing else

    • This reply was modified 7 years, 1 month ago by mrb1972.
    #870134

    Hi,

    @mrb1972
    thanks for sharing your solution with us.

    Best regards,
    Mike

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.