Created
May 18, 2020 05:17
-
-
Save ibndawood/6343bcdfd3a3253826a232a687c93c51 to your computer and use it in GitHub Desktop.
Electro v2 - Do not show brand if it does not have an image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function electro_template_single_brand() { | |
global $product; | |
$product_id = electro_wc_get_product_id( $product ); | |
$brands_tax = electro_get_brands_taxonomy(); | |
$terms = get_the_terms( $product_id, $brands_tax ); | |
$brand_img = ''; | |
if ( $terms && ! is_wp_error( $terms ) ) { | |
foreach ( $terms as $term ) { | |
$thumbnail_id = defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.6', '<' ) ? get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true ) : get_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]; | |
} | |
} else { | |
continue; | |
} | |
$image_src = str_replace( ' ', '%20', $image_src ); | |
$brand_img .= '<a href="' . esc_url( get_term_link( $term ) ). '"><img src="' . esc_url( $image_src ) . '" alt="' . esc_attr( $term->name ) . '" /></a>'; | |
} | |
} | |
if ( ! empty( $brand_img ) ) : ?> | |
<div class="brand"> | |
<?php echo wp_kses_post( $brand_img ); ?> | |
</div> | |
<?php endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment