• Resolved oramweb

    (@oramweb)


    Hi there.
    Nice plugin, upgraded with the loop brand name code.

    function pwb_show_brands_in_loop(){
    	global $product;
    	$product_id = $product->id;
    	$product_brands =  wp_get_post_terms($product_id, 'pwb-brand');
    	if(!empty($product_brands)){
    		echo '<div class="custom-loop-brands">';
    		foreach ($product_brands as $brand) {
    			echo '<span>'.$brand->name.'</span>';
    		}
    		echo '</div>';
    	}
    }
    add_action('woocommerce_before_shop_loop_item_title', 'pwb_show_brands_in_loop');

    Is there a way to show the image (logo) of the brand instead of the name?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor titodevera

    (@titodevera)

    Hi oramweb.

    Yes, here is the updated code, add it to your functions.php

    
     function pwb_show_brands_in_loop(){
    	global $product;
    	$product_id = $product->id;
    	$product_brands =  wp_get_post_terms($product_id, 'pwb-brand');
    	if(!empty($product_brands)){
    		echo '<div class="custom-loop-brands">';
    		foreach ($product_brands as $brand) {
    
    			echo '<span>';
    				$brand_link = get_term_link ( $brand->term_id, 'pwb-brand' );
    				$attachment_id = get_term_meta( $brand->term_id, 'pwb_brand_image', 1 );
    
    				$attachment_html = wp_get_attachment_image( $attachment_id, 'thumbnail' );
    				if(!empty($attachment_html)){
    					echo '<a href="'.$brand_link.'">'.$attachment_html.'</a>';
    				}else{
    					echo '<a href="'.$brand_link.'">'.$brand->name.'</a>';
    				}
    			echo '</span>';
    
    		}
    		echo '</div>';
    	}
    }
    add_action('woocommerce_before_shop_loop_item_title', 'pwb_show_brands_in_loop');
    

    Don´t forget to leave a review of the plugin 😉

    Thanks

    • This reply was modified 9 years, 5 months ago by titodevera.
    Thread Starter oramweb

    (@oramweb)

    Thank you very much! This made my day and looks very cool after some styling!

    View post on imgur.com

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Brand Image in Loop page’ is closed to new replies.