Configure, product_id and parent_category_id according to your requirements.
/* This is product id */
$product_id = 1;
/* This is the id of the parent category */
$parent_category_id = 8;
$cats = get_categories ( array (
'type' => 'product',
'parent' => $parent_category_id,
'orderby' => 'term_group',
'hide_empty' => true,
'hierarchical' = > 1,
'exclude' => '',
'property' => '',
'number' => '',
'taxonomy' => 'product_cat',
'pad_counts' => false
));
$non_empty_sub_categories_ids = array_map(create_function('$cat', 'return $cat->term_id;'), $cats);
$product_cats = get_the_terms( $product_id, 'product_cat' );
foreach ($product_cats as $product_cat) {
if(in_array($product_cat->term_id, $non_empty_sub_categories_ids)) {
echo '<a <br/> href="'. get_term_link($product_cat->slug,' product_cat ').' "> '. $product_cat->name.'</a>';
}
}