Okay
  Public Ticket #2035477
Search shows hidded products
Closed

Comments

  •  1
    minded started the conversation

    Hi,

    I know you have made it possible to limit what the search function searches for, posts, products etc.. But, correct me if I'm wrong, this limit still allows products with the visibility "hidden" to show up in the search results.

    Would it be possible to change the search function so that (if products is the only type that should be searched for) it prompts:
    [...]&post_type=product

    That way, hidden products are not included.

    Or is there another way?

    Thanks!

  • [deleted] replied

    Hi minded,

    As I know, the query results for products are filtered only when post_type=product parameter is added in the url, so to make this available in default search functionality please add the following code in functions.php:

    function kalium_woocommerce_tax_query_search_filter( $query ) {
        if ( function_exists( 'WC' ) && ! is_admin() && $query->is_main_query() ) {
            if ( $query->is_search ) {
                $query->set( 'tax_query', WC()->query->get_tax_query( $query->get( 'tax_query' ), true ) );
            }
        }
    }
    add_action( 'pre_get_posts', 'kalium_woocommerce_tax_query_search_filter' );
    

  •  1
    minded replied

    Worked perfectly!

  • [deleted] replied

    Hi minded,

    I'm happy to hear thatsmile.png

    P.S: If you like the theme, it would help us a lot if you could give us a five-star rating on Themeforest from your Downloads tab.

    A huge thank you from me and Laborator in advance <3