Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

Exclude woocommerce category from specific page

$
0
0

Replies: 0

I want to exclude all products/tours from the woocommerce category ‘Excursions’ (slug ‘excursions-ru’) on the ‘Our tours’ page (slug ‘our-tours-ru’).

I found this solution here So I use this code below, but it doesn’t work for me.

Can’t find where is my mistake.

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
// to hide from shop page, replace is_page('YOUR_PAGE_SLUG') with is_shop()
if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && 
is_page('our-tours-ru') ) {
foreach ( $terms as $key => $term ) {
if ( ! in_array( $term->slug, array( 'excursions-ru' ) ) ) {
$new_terms[] = $term;
  }
}
$terms = $new_terms;
}
return $terms;
}
  • This topic was modified 6 minutes ago by Merkucio.
  • This topic was modified 5 minutes ago by Merkucio.

Viewing all articles
Browse latest Browse all 59525

Trending Articles