Skip to content

Instantly share code, notes, and snippets.

@kloon
Created March 15, 2013 08:33
Show Gist options
  • Select an option

  • Save kloon/5168340 to your computer and use it in GitHub Desktop.

Select an option

Save kloon/5168340 to your computer and use it in GitHub Desktop.
WooCommerce display brand image on single product page
<?php
add_action( 'woocommerce_before_single_product', 'wc_brand_image_single_product' );
function wc_brand_image_single_product() {
global $post;
$brands = wp_get_post_terms( $post->ID, 'product_brand' );
if ( $brands )
$brand = $brands[0];
if ( ! empty( $brand ) ) {
$thumbnail = get_brand_thumbnail_url( $brand->term_id );
$url = get_term_link( $brand->slug, 'product_brand' );
echo '<a href="' . $url . '"><img class="woocommerce-brand-image-single" src="'. $thumbnail . '"/></a>';
}
}
?>
@ahmedelatab

Copy link
Copy Markdown

GREAT!

@shashupatankar007

Copy link
Copy Markdown

hii
this code is not working. please help??

@djbox9

djbox9 commented Feb 18, 2021

Copy link
Copy Markdown

everything gets blank

@ahmedelatab

ahmedelatab commented Feb 26, 2021 •

Copy link
Copy Markdown

@djbox9

Did you enable the debug and the debug display to check if there is any error?

Also make sure you have the WC Brands plugin!

@jaaacki

jaaacki commented Feb 14, 2022

Copy link
Copy Markdown

thanks

@mohmimi

mohmimi commented Jul 30, 2023

Copy link
Copy Markdown

Hello buddy,
thanks for sharing, can you please help me to add the product brand on the product view on home page for each product
Like this screenshot. https://prnt.sc/r1MuzsskJUqy

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment