Tagged: woocommerce
Hey,
I have a category that is showing up in my shop but I need to exclude it from there.
I found this, but i dosen’t seem to woork
https://kriesi.at/support/topic/hideexclude-a-category-from-woocommerce-shop-page/
The reason I would like it removed is that I want to show some selected products on the front slider, but they should only be visible there.
Hope you can help
Regards Pete,
Hey,
You can close this, i found this code – and it seems to work:
/* Exclude Category from Shop*/
add_filter( 'get_terms', 'get_subcategory_terms', 10, 3 );
function get_subcategory_terms( $terms, $taxonomies, $args ) {
$new_terms = array();
// if a product category and on the shop page
if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_shop() ) {
foreach ( $terms as $key => $term ) {
if ( ! in_array( $term->slug, array( 'cat1', 'cat2' ) ) ) {
$new_terms[] = $term;
}
}
$terms = $new_terms;
}
return $terms;
}
Regards Pete