How can I get the term_id from the action hook ‘set_object_terms’?

I finally found the solution to delete all the postmeta related to the term being deleted.

For this, we need to use the action hook 'delete_term_taxonomy' because it is executed before the term is deleted; therefore, we can find the term object and use it inside the hook.

Then, we proceed to perform certain task such as deleting all postmeta related to the term.

Here is the code:

add_action( 'delete_term_taxonomy', function($tt_id) {

    $taxonomy = 'category';    
    $term = get_term_by('term_taxonomy_id', $tt_id, $taxonomy); 
    $user_name = $term->name;
    $meta_key = "_category_relation_added_" . $user_name;
    delete_post_meta_by_key( $meta_key );

}, 9, 1);

tech