## Warning: Attempt to read property "term_id" on int – Woocommerce

Question

I would like to create a condition to manually hide product categories within the shop. I already started from a code base but I am trying to understand why if I put the is_product_category() condition the error comes out as I specified in the question with PHP Version 8.0

This is the code:

add_filter( 'get_terms', 'sct_hide_cat', 10, 3 );

function sct_hide_cat( $terms,$taxonomies, $args ) { global$product;
$exclude = [50, 22, 20, 31, 35, 45, 40, 65, 37, 40, 3434];$new_terms = [];

if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_shop() || is_product_category() ) { foreach ($terms as $key =>$term ) {
if ( ! in_array( $term->term_id,$exclude ) ) {
$new_terms[] =$term;
}
}
$terms =$new_terms;
}
return \$terms;
}

0
2 months 2022-08-10T03:01:19-05:00 0 Answers 0 views 0