-
-
Save celticwebdesign/d6350234c484233d6cb582afbe604cc3 to your computer and use it in GitHub Desktop.
WooCommerce - Display custom attributes on shop page - including attribute thumbnails
This file contains hidden or 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 | |
// this gist requires: http://candlestudio.net/woocommerce/plugins/button-variations/ | |
// a fork of: https://gist.github.com/croosen/24a2845f91ce91a2819b | |
// WooCommerce - Display custom attributes on shop page - the official way ;-) | |
global $wc_ea_term_meta; | |
// Get the attributes | |
$attributes = $product->get_attributes(); | |
// Start the loop | |
foreach ( $attributes as $attribute ) : | |
// Check and output, adopted from /templates/single-product/product-attributes.php | |
if ( $attribute['is_taxonomy'] ) { | |
if ( $attribute['name'] == "pa_colour" ) { | |
$values = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'ids' ) ); | |
echo "<div class='pa_colour'> | |
<ul>"; | |
foreach ( $values as $value ) : | |
$img_src = wp_get_attachment_image_src( get_option($wc_ea_term_meta . $value)['wc_ea_image'], 'full' ); | |
echo "<li><img src='".$img_src[0]."'></li>"; | |
endforeach; | |
echo " </ul> | |
</div>"; | |
} | |
} | |
endforeach; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment