Product Archive

WooCommerce Show Product Attribute On Archive Loop Items

WooCommerce product archive loop items showing attribute below the product name

Pre-Requisites

There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About This Solution

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 '<span class="onsale">' . $color_name . '</span>';
};

Snippet Benefits

  • Show a product attribute on the product archive loop items, allowing users to see more product detail without having to drill-down into the product.

100 WooCommerce Conversion Rate Optimisation Tips

This field is for validation purposes and should be left unchanged.

Let’s collaborate!

Need to outsource WordPress development?

Join forces with UnlimitedWP for an outsourced white label web development service you can truly rely on.

First Timer Here?

Sign up to receive 10% off on your first month with us.

26027
WELCOME OFFER