Last active
May 8, 2025 19:51
-
-
Save braddalton/4075e5611fda42acf90296799e3872d9 to your computer and use it in GitHub Desktop.
Add Thumbnail Images for Brands to the Single Product Page in WooCommerce https://wpsites.net/wordpress-tutorials/display-all-brand-thumbnails-on-product-page/
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
add_action( 'woocommerce_single_product_summary', 'display_all_brand_thumbnails_on_product_page', 25 ); | |
function display_all_brand_thumbnails_on_product_page() { | |
global $post; | |
$brands = wp_get_post_terms( $post->ID, 'product_brand' ); | |
if ( ! empty( $brands ) && ! is_wp_error( $brands ) ) { | |
// Output container for brand logos | |
echo '<div class="product-brand-thumbnails">'; | |
foreach ( $brands as $brand ) { | |
$thumbnail_id = get_term_meta( $brand->term_id, 'thumbnail_id', true ); | |
if ( $thumbnail_id ) { | |
$image_url = wp_get_attachment_image_url( $thumbnail_id, 'full' ); | |
if ( $image_url ) { | |
echo '<img class="brand-logo" src="' . esc_url( $image_url ) . '" alt="' . esc_attr( $brand->name ) . '" />'; | |
} | |
} | |
} | |
echo '</div>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment