Warning: Attempt to read property "term_id" on int - Woocommerce

rawsar

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

This is the code:

PHP:
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;

}

Any solution?
 

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu