Forums Forums Search & Filter Pro Include hidden woocommerce product in search results

Viewing 6 posts - 1 through 6 (of 6 total)
  • Anonymous
    #229563

    Hi there.

    I have a quite special use case for which I caould not find a solution even so I am quite sure there must be one. I a planning to have eclusive products which shall only be visible on a special page. So I hide them from my main shop page with visibility = hidden – and I figured out there is a meta value _visibility … but I can not get my search form to display these hidden products with my searchform on the custum site.

    One more info I already found and tested: Using a simple woocommerce shortcode to display the hidden product works: [products limit=”4″ columns=”4″ orderby=”popularity” class=”quick-sale” tag=”christmas-club ” visibility=”hidden” ] – but using the shortcode I have no filtering…

    I hope you can tell me what I need to do to include hidden products in my search and results 🙂

    Trevor
    #229577

    Rather than using visibility, I think you would need to make a custom field (I use ACF for custom fields) and then make sure ALL products have a value for this field. Then use that field to designate Exclusive or not.

    Anonymous
    #229610

    Hi Trevor,

    but how do I make sure that these products are not shown / included on the main shop page, if I do not use visibility? As the shop is usually meant to be showing all visible products…

    Best wishes
    Miriam

    Trevor
    #229623
    This reply has been marked as private.
    Anonymous
    #229642

    Hi Trevor,

    I tried some things and fiugred out it seems to be easier to not make sure the products are not being displayed om the main shop page. Using the pre_get_posts hook works for me as I am displaying my search results by shortcode and in this case pre_get_posts does not seem to be fired…

    Here is the code I added to my child theme’s functions.php:

    function mk_custom_pre_get_posts_query( $q ) {
    $tax_query = (array) $q->get( ‘tax_query’ );
    $tax_query[] = array(
    ‘taxonomy’ => ‘product_tag’,
    ‘field’ => ‘slug’,
    ‘terms’ => array( ‘christmas-club’ ),
    ‘operator’ => ‘NOT IN’
    );
    $q->set( ‘tax_query’, $tax_query );
    }
    add_action( ‘woocommerce_product_query’, ‘mk_custom_pre_get_posts_query’ );

    ______________________

    I have one more thing you maybe could help me with: Is there an easy way to make sure that the results are displayed as woocoomerce products (same layout as on the main shop-page)?

    Best wishes
    Miriam

    Trevor
    #229644

    What Display Results Method are you using?

    The WooCommerce method should do as you ask, and the As an Archive you can specify the template. The custom method allows you to direct the results to a specific page, and as long as you have within WordPress or your theme specified that template, all will be good. The custom method also allows you to add to pre_get_posts. See here:

    https://searchandfilter.com/documentation/search-results/custom/#pre_get_posts

Viewing 6 posts - 1 through 6 (of 6 total)