Home Forums WoodMart support forum Brand image on product archive Reply To: Brand image on product archive

#39207

Artem Temos
Keymaster

Try to replace the previous code with this one

function brands_in_loop(){
	global $product;
	$output = array();
	$product_brands = wp_get_post_terms( $product->get_id(), 'pa_brand' );
	echo '<div class="custom-loop-brands">';
		foreach ( $product_brands as $brands ) {
			$image = get_term_meta( $brands->term_id, 'image', true );
			if ( $image ) {
				echo '<span class="marca-archivos"><img src="' . esc_url( $image ) . '" title="' . esc_attr( $brands->slug ) . '" alt="' . esc_attr( $brands->slug ) . '" /></span>';
			}else{
				echo '<span class="marca-archivos">' . $brands->name . '</span>';
			}
		}
	echo '</div>';
}
add_action( 'woocommerce_shop_loop_item_title', 'brands_in_loop', 5 );