If you have a term, you can retrieve its meta via get_term_meta
, this function works the same way as get_post_meta
only it takes a term ID not a post ID
E.g.
if ( get_term_meta( $term_id, 'key', true ) === 'value' ) {
// it has the value
}
Once you know this, it's just basic logic of looping over each term and checking them, which you already do in the code in your question