WordPress.org

Forums

WooCommerce - excelling eCommerce
wooCommerce search is searching whole site, need products only (13 posts)

  1. Brandon Sheley
    Member
    Posted 1 year ago #

    I'm working on a site and the person that touched it before me messed up a search box somehow on our product page. How can I setup a search box to search the woocommerce products only?

    I looked at the search widget to compare the code but everything I've tried hasn't worked.

    Thanks
    -Brandon

    http://wordpress.org/plugins/woocommerce/

  2. Brandon Sheley
    Member
    Posted 1 year ago #

    Anyone with suggestions on this issue?

    Thanks

  3. rcards
    Member
    Posted 1 year ago #

    I'd like to know the same thing! :)

  4. sta777
    Member
    Posted 1 year ago #

    Try this:

    <form action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get">
         <input name="s" type="text" value="Enter product name..."  onblur="this.value = this.value || this.defaultValue;" onfocus="this.value = '';" />
         <input type="submit" value="Search" />
         <input type="hidden" name="post_type" value="product" />
    </form>
  5. zanpo
    Member
    Posted 9 months ago #

    Hello! Sorry to bump this old thread, but I have the same problem. I used the code suggested by sta777, but still no luck.

    My search link is this type: "site.com/?s=keyword", but I need it to be like this: "site.com/?s=keyword&post_type=product".

    Any suggestions?

    Thanks

  6. sta777
    Member
    Posted 9 months ago #

    The code I posted does work and will display "site.com/?s=keyword&post_type=product" in the address bar.

    Where are you using the code? Have you copied it in full?

  7. zanpo
    Member
    Posted 9 months ago #

    Hi, sta777, thanks for the quick response.

    Actually I edited the code a little bit and used it like this, so it has a nice design for my theme:

    <div id="headersearchform-container" class="group">
        <form role="search" method="get" id="headersearchform" action="<?php echo esc_url( home_url( '/' ) ); ?>" >
            <div class="group formborder">
                <input  type="text" value="" name="s" id="headers" placeholder="Ce produs cauti astazi?" />
                <input  type="submit" class="button" id="headersearchsubmit" value="Cauta" />
            </div>
            <input type="hidden" name="post_type" value="product" />
        </form>
    </div>

    And used it via a snippet in my home page. But it still has the part with:

    <input type="hidden" name="post_type" value="product" />

    Which causes the "&post_type=product" to appear, no?

    Also the problems with my searches are a little bigger, if I try to search by a keyword with spaces in between, like "key%20word", my search link looks like "http://site.com/?s=key%20word" and goes in an infinite loop.

    The search.php and searchfrom.php are the theme's default:

    Here is searchform.php: http://pastebin.com/UHU8Bghm

    Here is search.php: http://pastebin.com/d3znLznz

  8. sta777
    Member
    Posted 9 months ago #

    Have a look at this and see if it helps - http://www.remicorson.com/customize-woocommerce-products-search-form/

    :)

  9. zanpo
    Member
    Posted 9 months ago #

    I tried with the filter and the product-searchform.php file, nothing seems to work. The searches are the same, with no post_type.
    I tried it with twentytwelve theme and still no change, I guess this is not an error from my theme, but maybe from the woocommerce plugin?

  10. sta777
    Member
    Posted 9 months ago #

    Are you getting any search results back at all?

  11. zanpo
    Member
    Posted 9 months ago #

    yes, results are showing, but only when i use a single keyword, if I search for something with spaces in between like "black shoes" for example, it gets into an infinite loop.

  12. sta777
    Member
    Posted 9 months ago #

    Sounds like you may have an error in your loop...

  13. zanpo
    Member
    Posted 9 months ago #

    Problem solved! It was an error form YOAST SEO plugin, I had ticked the boxes for '?replytocom' and 'Redirect ugly URL's to clean permalinks. (Not recommended in many cases!)', under the 'permanent links' menu.
    As soon as I unticked them, the searches work perfect and &post_type=product is back in his place.
    Thanks for the help and suggestions sta777 :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.