Advertisement
Guest User

Hide products from a particular product category in shop page WooCommerce

a guest
Sep 27th, 2022
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. add_action( 'woocommerce_product_query', 'ts_custom_pre_get_posts_query' );
  2. function ts_custom_pre_get_posts_query( $q ) {
  3. $tax_query = (array) $q->get( 'tax_query' );
  4. $tax_query[] = array(
  5. 'taxonomy' => 'product_cat',
  6. 'field' => 'slug',
  7. 'terms' =>array( 'free' ), // Don't display products in the free category on the shop page.
  8. 'operator' => 'NOT IN'
  9. );
  10. $q->set( 'tax_query', $tax_query );
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement