Skip to content

Instantly share code, notes, and snippets.

@kartikparmar
Created September 11, 2019 05:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kartikparmar/453e0a268e1452ff955dc84cf9991cc6 to your computer and use it in GitHub Desktop.
Save kartikparmar/453e0a268e1452ff955dc84cf9991cc6 to your computer and use it in GitHub Desktop.
Removing products from a particular category on the shop page.
<?php
function hpcs_hide_products_category_shop( $query ) {
$tax_query = (array) $query->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'chairs' ), // Category slug here
'operator' => 'NOT IN'
);
$query->set( 'tax_query', $tax_query );
}
add_action( 'woocommerce_product_query', 'hpcs_hide_products_category_shop' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment