plugins – affixing a parent category when importing xml into woocommerce

I configure import according to this manual.Categories are imported without hierarchy, all at the same level. What needs to be corrected in the code so that the hierarchy is taken into account when importing?

function my_get_category( $id ) {
$term = get_terms( array(
        'taxonomy' => 'product_cat',
        'hide_empty' => false,
        'meta_query' => array(
            array(
                'key'       => '_category_id',
                'value'     => $id,
                'compare'   => '='
            )
        )
    )
);
if ( ! empty( $term ) ) {
    return $term(0)->slug;
}       
}

I suppose that this can somehow be implemented through get_ancestors () or get_term_meta ()
but there is no understanding how to do this. please help