In Woocommerce, I have added a hooked function which displays the product attribute for variation assigned to a variable product on the Woocommerce archive pages:
add_action( 'woocommerce_after_shop_loop_item', 'stock_variations_loop' );
function stock_variations_loop(){
global $product;
if ( $product->get_type() == 'variable' ) {
foreach ($product->get_available_variations() as $key) {
$attr_string = '';
foreach ( $key['attributes'] as $attr_name => $attr_value) {
$attr_string[] = $attr_value;
}
if ( $key['max_qty'] > 0 ) {
echo '<div class="sizeVariantCat">' . implode(', ', $attr_string).'</div>';
}
}
}
}
It is working fine, but some of the data is messy… I only want to display 'Size' product attribute for variation values, not all the products that have a "size" attribute.