Skip to content

Instantly share code, notes, and snippets.

@celticwebdesign
Forked from croosen/content-product.php
Last active April 3, 2024 12:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save celticwebdesign/d6350234c484233d6cb582afbe604cc3 to your computer and use it in GitHub Desktop.
Save celticwebdesign/d6350234c484233d6cb582afbe604cc3 to your computer and use it in GitHub Desktop.
WooCommerce - Display custom attributes on shop page - including attribute thumbnails
<?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