Skip to content

Instantly share code, notes, and snippets.

@glueckpress
Last active December 14, 2015 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save glueckpress/357e4e4242647191b4a0 to your computer and use it in GitHub Desktop.
Save glueckpress/357e4e4242647191b4a0 to your computer and use it in GitHub Desktop.
[WordPress] WooCommerce: Display product variation attributes on product category pages.
<?php
/*
* Regular content of content-product.php
* ...
* ...
*/
/**
* Display product variation attributes on product category pages.
*
* Add i.e. after do_action( 'woocommerce_after_shop_loop_item_title' );
* Can also be hooked from outside the template.
*/
if( is_product_category() ) :
$attributes = $product->get_attributes();
foreach ( $attributes as $attribute ) :
if ( empty( $attribute['is_variation'] ) || ( $attribute['is_taxonomy'] && ! taxonomy_exists( $attribute['name'] ) ) )
continue;
else
printf( '<span class="product-attribute">%s</span>', wc_attribute_label( $attribute['name'] ) );
endforeach;
endif;
/*
* More of content of content-product.php
* ...
* ...
*/
@flamingoezz
Copy link

I've tried adding this to my content-product page. Should I be changing something within your code to target a specific attribute?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment