Incomplete term slugs output from a foreach loop with get_the_terms

You are overwriting $product_cat_slugs on every iteration of your loop – so when it’s finished, that variable will be set to the last value.

Why not do all of your outputs inside that loop?

Or if for some reason you don’t want to do that, make $product_cat_slugs an array instead of a variable:

$product_cat_slugs = [];
foreach ($terms as $term) {
    $product_cat_slug = $term->slug;
    $product_cat_slugs[] = ' product_cat-' . $product_cat_slug;
}

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