Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save wbcomdev/ae20d9a8808c989ea7fc3aad75a54cf2 to your computer and use it in GitHub Desktop.

Select an option

Save wbcomdev/ae20d9a8808c989ea7fc3aad75a54cf2 to your computer and use it in GitHub Desktop.
<?php
/**
* Remove products from a particular category on the shop page.
*/
function wbcom_remove_product_from_specific_category( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'music' ), // change or add the category slug here.
'operator' => 'NOT IN',
);
$q->set( 'tax_query', $tax_query );
}
add_action( 'woocommerce_product_query', 'wbcom_remove_product_from_specific_category' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment