Skip to content

Instantly share code, notes, and snippets.

@spasicm
Last active September 27, 2021 15:17
Show Gist options
  • Save spasicm/45aa90c628eda671e68e1722ee0ff8e6 to your computer and use it in GitHub Desktop.
Save spasicm/45aa90c628eda671e68e1722ee0ff8e6 to your computer and use it in GitHub Desktop.
WooCommerce Brands - display brand image on single product page
<?php
// This is add-on for official WooCommerce Brands plugin -> https://woocommerce.com/products/brands/
// To make this add-on to work, all code must be added to WP functionality plugin -> https://css-tricks.com/wordpress-functionality-plugins/
add_action( 'init', 'eworkshop_remove_actions' );
function eworkshop_remove_actions() {
// WooCommerce remove brand from single product page
remove_action( 'woocommerce_product_meta_end', array( $GLOBALS['WC_Brands'], 'show_brand' ) );
}
// WooCommerce display brand image on single product page
add_action( 'woocommerce_product_meta_end', 'wc_brand_image_single_product', 999 );
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' );
$name = esc_attr( $brand->name );
echo '<span class="posted_in">Brand: <br><a href="' . $url . '"><img class="woocommerce-brand-image-single" src="'. $thumbnail . '" alt="' . $name . '" style="max-width:150px;"></a></span>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment