You can use is_category()
You can check the documentation here
function show_parent_categories( $args = array() ) {
$args = array(
'hierarchical' => 1,
'show_option_none' => '',
'hide_empty' => 0,
'parent' => $category->term_id,
'taxonomy' => 'product_cat'
);
$product_categories = get_terms( 'product_cat', $args );
$count = count($product_categories);
if ( $count > 0 ){
echo "<div id='main-categories-wrapper'><ul id='main-categories'>";
foreach ( $product_categories as $product_category ) {
echo '<li><a class="'.(is_category($product_category->slug)?'active':'').'" href="' . get_term_link( $product_category ) . '">' . $product_category->name . '</li>';
}
echo "</ul></div>";
}
}