How to add subcategories to templates in WordPress

This is the snippet I have added to my category template in my blog’s child theme. I paste the following snippet usually after the taxonomy-description paragraph. This is how it looks (the two paragraphs Parents and Subcategories):

category-parents-and-subcategories

This is the code:

<?php
    // Parents
    $parents = get_category_parents($cat, true, " +++ ");
    $parents = explode(" +++ ", $parents);
    $parents = array_slice($parents, 0, -2);
?>
<?php if ( count($parents) > 0 ) : ?>
<div class="taxonomy-parents"><em>Parents:</em> <?php print(implode(', ',$parents)); ?></div>
<?php endif; ?>

<?php
    // Subcategories
    $list = wp_list_categories('depth=-1&orderby=name&style=none&echo=0&title_li=&child_of='.$cat); 
    $list = substr(trim(str_replace('<br />', ', ', $list)), 0, -1); // replace newlines by commas, trim whitespace, cut of final comma
?>
<?php if ( !preg_match("/No categorie/",$list) ) : ?>
<div class="taxonomy-subcategories"><em>Subcategories:</em> <?php echo $list; ?></div>
<?php endif; ?>