This snippet allows you to get the WooCommerce product attributes and output them on the product archive loop items below the product name. In this particular example, we output the “color” product attribute. To output any other attribute, you’ll need to navigate to Dashboard > Products > Attributes > Create your attribute then configure your terms. You’ll see in the url a taxonomy parameter. Take the value from this parameter and replace pa_color in the code to output your attribute. You’ll see we’ve wrapped the output in the sale badge span class just to make it that little bit more presentable.
/**
* Snippet Name: WooCommerce Show Product Attribute On Archive Loop Items
* Snippet Author: ecommercehints.com
*/
add_action( 'woocommerce_after_shop_loop_item_title', 'ecommercehints_show_product_attributes_on_arhive_loop_item', 1, 0 );
function ecommercehints_show_product_attributes_on_arhive_loop_item() {
global $product;
$product = wc_get_product( get_the_id() );
$product_attributes = $product->get_attributes();
$color_id = $product_attributes['pa_color']['options']['0']; // returns the ID of the term. You will need to change 'pa_color' to your taxonomy attribute ID.
$color_name = get_term( $color_id )->name;
echo '' . $color_name . '';
};