Been trying to figure out how I can get the product attributes of the current product and store it in a variable and put it in a class.
I've managed to get the product attributes, unfortunately it seems to be displaying all the products attributes to all the products I have set. Here is the code I have been working.
<div id="Container" class="nine columns mixitup-container bevtools-liquor">
<?php
$liquor = new WP_Query( array(
'post_type' => 'product',
'product_cat' => 'liquors',
'meta_query' => array(
array(
'key' => '_stock_status',
'value' => 'instock'
)
)
) );
if ( $liquor->have_posts() ) : while ( $liquor->have_posts() ) : $liquor->the_post();
?>
//In this foreach loop, I'm trying to get all the terms for liquor-brands attributes
<?php
$brand_terms = get_the_terms( $post, 'pa_liquor-brands' );
foreach ( $brand_terms as $term ) :
?>
<?php $brand_string = ''; ?>
<?php $brand_string .= $term->slug . ' '; ?>
<?php endforeach; ?>
<div id="post-<?php the_ID(); ?>" class="three columns mix product-post <?php echo $brand_string ?>" >
</div>
<?php wp_reset_postdata(); ?>
<?php endwhile; else: ?>
<?php //error message ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
After running the code here is what the output looks like.
<div id="post-2190" class="34th-pursuit-joes-brew absolut aviation-gin bacardi botanist citadelle-gin don-papa gvine grey-goose jack-daniel johnnie-walker makers-mark monkey-shoulder pale-ale-katipunan" style="display: inline-block;" data-bound="">
</div>
<div id="post-2192" class="34th-pursuit-joes-brew absolut aviation-gin bacardi botanist citadelle-gin don-papa gvine grey-goose jack-daniel johnnie-walker makers-mark monkey-shoulder pale-ale-katipunan" style="display: inline-block;" data-bound="">
</div>
As you can see both products are showing all the product attributes instead of showing what is assigned to them instead.