PHP Warning (WC sub-categories in “Terms (cloud)”)

Hi,
I am writing to reopen the topic WC sub-categories in "Terms (cloud)" because of the log file of the site https://look4hair.com, where I applied the code suggested here WC sub-categories in "Terms (cloud)" I see this error:

PHP Warning: Undefined property: WP_Post_Type::$term_id

How could I solve it?
Thanks

Hello @scenaryo,

Thank you for the inquiry.

We adjusted the cs_looper_custom_subcat slightly and added a condition to check if $category exists. Please replace the existing filter with this:

add_filter('cs_looper_custom_subcat', function($result, $args) {
    $category = get_queried_object();

    if (!$category || !isset($category->term_id)) {
        return []; 
    }

    $cat_args = array(
        'hide_empty' => 1,
        'child_of'   => $category->term_id,
        'taxonomy'   => 'product_cat',
    );

    $subcats = get_categories($cat_args);

    return $subcats;
}, 10, 2);

Let us know if this resolves the issue.

Best regards,
Ismael

Hi @Ismael,
the warning is no longer in the log file so I think you solved it.
Thanks a lot!

Great! Glad to know that the issue has been resolved. Let us know if you have more questions.