• Resolved KatrineDS

    (@katrineds)


    Hi,
    Does anyone know how to change the default search form to search in products ?
    So taht the search results is shown as products instead of plain text?
    Something in functions.php perhaps?? I’ve read a lot – but it looks like it’s theme dependent – and I’m not confident to try to change the code.

Viewing 3 replies - 1 through 3 (of 3 total)
  • @katrineds

    If you can code on your own then you can achieve it via the child theme.

    Thanks.

    Thread Starter KatrineDS

    (@katrineds)

    Hi Nitu,
    Thanks for your answer.
    As I wrote I cannot code it myself. I’ve found solutions for other themes – but not for Flash. I always use Flash for my clients. I LOVE Flash – but it’s a big minus, that the search function doesn’t work for products. Can you point me in the right direction? I mean more like a code snippet, than the placement of it. Would really appreciate that! 🙂

    Thread Starter KatrineDS

    (@katrineds)

    Never mind – I found a snippet. Works like a charm!
    Perhaps it can help others.

    Goes in functions.php

    add_action( 'pre_get_posts', 'wpse223576_search_woocommerce_only' );
    
    function wpse223576_search_woocommerce_only( $query ) {
      if( ! is_admin() && is_search() && $query->is_main_query() ) {
        $query->set( 'post_type', 'product' );
      }
    }
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Replace default search with Woo search’ is closed to new replies.