Add 3rd level to Categories lists

I have a 2 level list of categories displaying checkboxes for a filter.

<?php       
$terms = get_categories( array(
  'orderby' => 'meta_value',
  'meta_key' => 'orden', 
 'parent'  => 0,
    'hide_empty' => 0,  
    'exclude' => 1,  
     ) );
echo '<ul>';
        foreach ($terms as $term) {
        $categories = get_categories('child_of='.intval($term->term_id));
        echo '<li class="desplegable"><label class="desp" for="termino_' . $term->slug . '">' . $term->name . '</label>';
        
            echo '<ul class="cat-submenu">';
        foreach ($categories as $category) {
        if ($category->parent==$term->term_id):
        echo '<li class="submenu-item"><input type="checkbox" id="termino_' . $category->slug . '" name="termino_' . $category->slug . '" /><label for="termino_' . $category->slug . '">' .$category->cat_name. '</label></li>';
        
        endif;
    }
    echo '</ul>';
    echo '</li>';
    }
echo '</ul>';
    ?>

Now I need to include a 3rd level but with no result. Any tips?
Thank you in advance

Go to Source
Author: Juárez