Forums › Forums › Search & Filter Pro › Include hidden woocommerce product in search results
- This topic has 5 replies, 2 voices, and was last updated 5 years, 3 months ago by
Trevor.
-
Anonymous(Private) December 19, 2019 at 11:03 pm #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 🙂
Anonymous(Private) December 22, 2019 at 3:14 am #229642Hi 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
MiriamTrevor(Private) December 22, 2019 at 7:48 am #229644What 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
-
AuthorPosts