Last active
December 14, 2015 21:39
-
-
Save glueckpress/357e4e4242647191b4a0 to your computer and use it in GitHub Desktop.
[WordPress] WooCommerce: Display product variation attributes on product category pages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
* ... | |
* ... | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've tried adding this to my content-product page. Should I be changing something within your code to target a specific attribute?