get product attributes for current product and store it in a variable

get_terms() Retrieves the terms in a given taxonomy or list of
taxonomies.

What you need is

get_the_terms() Retrieves the terms of the taxonomy that are attached
to the post
.

So you can simply replace

$brand_terms = get_terms( 'pa_liquor-brands' );

with

$brand_terms = get_the_terms( $post, 'pa_liquor-brands' );

And that should to the trick.

You can read more about these two functions here:

https://developer.wordpress.org/reference/functions/get_terms/
https://developer.wordpress.org/reference/functions/get_the_terms/

Edit:
And you will also need to reset your $brand_string otherwise it will add terms from another posts and output them

$brand_terms = get_the_terms($post, 'pa_liquor-brands');
$brand_string = ''; // Reset string
foreach ($brand_terms as $term) :
    $brand_string .= $term->slug . ' ';
endforeach;

// echo $brand_string down here somewhere

Leave a Comment