Reply 309813 to: How to display brand’s description in sidebar

Avatar: Olga Barlow
Olga Barlow
Support staff
November 25, 2021 at 12:03

Hello,

1) Add the below code to child theme functions.php

add_shortcode('product_brand_single', 'et_product_brand_single');
function et_product_brand_single() {
	global $post, $wpdb, $product;
    $terms = wp_get_post_terms( $post->ID, 'brand' );   
    if(count($terms)>0) {
    	?>
		<div class="product-brands">
			<h4 class="widget-title"><span><?php esc_html_e('Product brand', 'royal-core') ?></span></h4>
        	<?php
		        foreach($terms as $brand) {
		            $image 			= '';
		        	$thumbnail_id 	= absint( get_term_meta( $brand->term_id, 'thumbnail_id', true ) );
		        	?>
                	<a href="<?php echo get_term_link($brand); ?>">
			        	<?php
			        	if ($thumbnail_id) :
			        		$image = etheme_get_image( $thumbnail_id );
			                ?>
			                		<?php if($image != ''): ?>
			                    		<img src="<?php echo $image; ?>" title="<?php echo $brand->name; ?>" alt="<?php echo $brand->name; ?>" class="brand-image" />
			                    	<?php else: ?>
			                    		<?php echo $brand->name; ?>			                    		
			                    	<?php endif; ?>
			                <?php
			            else :
			            	echo $brand->name;
			        	endif; ?>
			        	<div class="brand-description text-center">
                        <p><?php echo wp_specialchars_decode( $brand->description ); ?></p></div>
                	</a>
                	<?php
		        }
        	?>
		</div>
    	<?php
    }
}

2) Add below code to child theme style.css

.single-product-sidebar .sidebar-widget.product-brands {
    display: none;
}
.brand-description p {
    font-size: 14px;
}

3) Add below shortcode to Appearance > Widgets > Single product sidebar
[product_brand_single]

Regards

Go To The Whole Conversation In Topic
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.