I would need your help as I am unable to hide subcategories, or rather, child categories of already hidden and defined categories.
I tried entering $args['parent'] = 0; but it hides all the parent categories. I've also tried $args['exclude_tree'], but for some unknown reason, it crashes and won't let me move on.
I would be grateful if someone could help me out.
This is the function:
add_filter( 'get_terms_args', 'mamaduka_edit_get_terms_args', 10, 2 );
/**
* Exclude product categories from Woocommerce
*/
function mamaduka_edit_get_terms_args( $args, $taxonomies ) {
//print_r($taxonomies);
//print_r($args);
if ( is_admin() && 'product_cat' !== $taxonomies )
return $args;
$args['exclude'] = [50, 22, 20, 31, 35, 45, 40, 65, 37, 40, 3434]; // Array of cat ids you want to exclude
$args['parent'] = 0;
return $args;
}