Using wp_list_pluck
to return an array in the form of array(term_id => parent, ...)
, you can do the following (explanation is given in the comments):
$variations = get_the_terms( the_ID() , 'product_cat' );
if(is_array($variations)) { //make sure terms were returned
$parents = wp_list_pluck( $variations, 'parent', 'term_id' );
foreach ($variations as $variation) {
if($variation->parent && $parents[$variation->parent] && !$parents[$parents[$variation->parent]]) { //if parent's parent has no parent (parent==0) i.e. a top level term (0 evaluates to false when treated as a boolean)
//display term
}
}
}