Skip to content

Instantly share code, notes, and snippets.

@jmabbas
Last active April 29, 2025 12:57
Show Gist options
  • Save jmabbas/753e58ace24dd7fffbcb6becfe4b4f0d to your computer and use it in GitHub Desktop.
Save jmabbas/753e58ace24dd7fffbcb6becfe4b4f0d to your computer and use it in GitHub Desktop.
Bookworm - Brand image on Single product page
function bookworm_wc_single_product_author() {
global $product;
$product_id = $product->get_id();
$brands_tax = bookworm_get_book_author_taxonomy();
$terms = get_the_terms( $product_id, $brands_tax );
$brand_html = '';
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
$thumbnail_id = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true );
if ( $thumbnail_id ) {
$image_attributes = wp_get_attachment_image_src( $thumbnail_id, 'full' );
if( $image_attributes ) {
$image_src = $image_attributes[0];
}
$image_src = str_replace( ' ', '%20', $image_src );
$brand_img = '<img src="' . esc_url( $image_src ) . '" alt="' . esc_attr( $term->name ) . '" />';
} else {
$brand_img = '';
}
$brand_html .= '<a href="' . esc_url( get_term_link( $term ) ). '">' . $brand_img . '</a>';
}
}
$author_name = bookworm_wc_get_product_author();
if ( ! empty ( $author_name ) ) :
?><div class="d-flex align-items-center" style=" margin-right: 20px; "><span class="font-weight-medium"><?php echo esc_html__('By (author)', 'bookworm');?></span><span class="ml-2 text-gray-600"><?php echo wp_kses_post( str_replace( '</a><a ', '</a>, <a ', $author_name ) ); ?></span></div><?php
endif;
print_r($brand_html);
?>
<div class="author-single-desc" style="width: 100%; margin-top: 10px;">
<?php echo $terms[0]->description; ?>
</div>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment