On archive.php show loop for child categories if they exist or posts if they don’t, on custom post type

This works, anything better would be appreciated

$term = get_queried_object();
$term_id = $term->term_id;
$taxonomy_name = $term->taxonomy;
$termchildren = get_term_children( $term_id, $taxonomy_name );
if (!empty($termchildren)) {
echo '<div class="subcatwrapper">';
echo '<ul class="workshopgrid centerWidth">';
foreach ( $termchildren as $child ) {
$term = get_term_by( 'id', $child, $taxonomy_name );
echo '<li class="workshopbox">';
echo '<div class="workshopimage"><a href="'. get_term_link( $term->slug, $term->taxonomy ) .'" ><img  src="'.get_field('category_image', $term->taxonomy . '_' . $term->term_id).'"/></a></div>';
echo '<div class="workshopTitle"><h6><a href="'.get_term_link( $term ->slug, $term ->taxonomy ).'">';
echo $term ->name.'</a></h6></div>';
echo '<div class="workshopTitle"><p>'.$term->description.'</p></div>';
echo '<div class="workshopButton"><p><a href="'. get_term_link( $term ->slug, $term ->taxonomy ).'" class="whiteButton">Discover More</a></p></div>';
}
echo '</ul></div>';
} elseif (have_posts() && (!!empty($termchildren))) {
    echo '<div class="centerWidth centreme">';
//echo do_shortcode ('[searchandfilter id="7085"]');
echo '</div><div class="workshopwrapper"><ul class="workshopgrid centerWidth">';
while (have_posts()) : the_post(); 
echo '<li class="workshopbox"><div class="workshopimage">';
echo '<div class="article">';
echo '<div class="blogthumbnail"><a href="';
echo get_the_permalink($post->ID);
echo '">';
echo the_post_thumbnail($size="letterbox").'</a></div>';
echo '<div class="workshopTitle"><h6><a href="';
echo get_the_permalink($post->ID);
echo '">';
echo get_the_title($post->ID);
echo '</a></h6></div><div class="workshopTitle"><p>';
echo the_excerpt();
echo '</p></div><div class="workshopButton"><p><a href="';
echo get_the_permalink($post->ID);
echo '" class="whiteButton">Discover More</a></p></div></div></div></li>';
endwhile;
echo '</ul></div>';
echo '<div class="navigation centerWidth clearfix">';
echo the_posts_pagination( array(
    'mid_size'  => 2,
    'prev_text' => __( '<', 'textdomain' ),
    'next_text' => __( '>', 'textdomain' ),
) );
} else {
echo '<h6><'._e('Sorry, no posts matched your criteria.').'</h6>';
}