Skip to content

Instantly share code, notes, and snippets.

@bjornpatje
Last active January 9, 2023 15:52
Show Gist options
  • Save bjornpatje/1bf82763c7d64966fb73769485df98a7 to your computer and use it in GitHub Desktop.
Save bjornpatje/1bf82763c7d64966fb73769485df98a7 to your computer and use it in GitHub Desktop.
<?php
// Add attribute images on shop page with products
function display_attribute_images() {
global $product;
$attributes = $product->get_attributes();
echo '<div class="attribute-image-wrapper" style="display:flex;flex-direction:row;justify-content:center;">';
foreach ( $attributes as $attribute ) {
$name = $attribute['name'];
$options = $attribute['options'];
foreach ( $options as $option ) {
$image = wp_get_attachment_image( get_term_meta( $option, 'ux_image', true ), 'thumbnail' );
if ( $image ) {
echo '<div class="attribute-image" style="width:50px;margin-right:5px;">' . $image . '</div>';
}
}
}
echo '</div>';
}
add_action( 'woocommerce_before_shop_loop_item_title', 'display_attribute_images', 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment