Display div if category has a specific parent

So effectively, I’m now able to set a parent category ID, and have all the products that exist in subcategories within that parent ID echo my desired content – definitely open to any suggestions or improvements here!

I’m using this in a function, which is placing the ‘tt’ div on my target product pages in a specified place (depending on priority).

The foreach loop is pulling category IDs, then checking the resulting $term against a parent ID stipulated in the if statement (60 in this case).

function test($term) {
    global $product;
    global $post;
    $terms = get_the_terms( $post->ID, 'product_cat' );
    
    foreach ($terms as $term) {
    $product_cat_id = $term->term_id;
    if ( $term->parent == 60 ) 
    {
        echo '<div class="tt">test</div>';}
    }
}