Get term slug by term id and then explode it

I guess the problem is here.

$slug = $term->slug;
$explodedSlug = explode('-', $_slug);

you are passing an undefined array $_slug to explode function. the correct array is $slug. so your complete code should be something like below.

function revised_featured_courses_query() {
$meta_query  = WC()->query->get_meta_query();
$tax_query   = WC()->query->get_tax_query();
$tax_query[] = array(
    'taxonomy' => 'product_visibility',
    'field'    => 'name',
    'terms'    => 'featured',
    'operator' => 'IN',
);
$args = array(
    'post_type'   =>  'product',
    'stock'       =>  1,
    'showposts'   =>  3,
    'orderby'     =>  'rand',
    'order'       =>  'DESC',
    'meta_query'  =>  $meta_query,
    'tax_query'   => $tax_query
);

$featured_query = new WP_Query( $args );

    if ($featured_query->have_posts()) :

        $html_out="<ul class="products">";

        while ($featured_query->have_posts()) : $featured_query->the_post();

            $id = get_the_ID(); // or use $post->ID
            $terms = get_the_term( $id, 'product_cat' );

            foreach ($terms as $term ) {
              $slug = $term->slug;
              $explodedSlugs[] = explode( '-', $slug );
            }
            // Your other codes goes here.


            $html_out .= '<li class=""><div class="entry-product">';
            $html_out .= '<div class="course-level">';
            foreach ($explodedSlugs as $slug ) {
              $html_out .= $slug[1];
            }
            $html_out .= '</div>';

            $html_out .= '</div></li>';

        endwhile;
        $html_out .= '</ul>';

    endif;

    //wp_reset_query();
    return $html_out;
    }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)