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, 6 months ago by
Trevor.
-
Anonymous(Private) December 22, 2019 at 3:14 am #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
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