Created
May 18, 2020 05:20
-
-
Save ibndawood/49b766050ad365bff957a112fde9ea8e to your computer and use it in GitHub Desktop.
Electro v2 - Change the default placeholder image for Brands in Single Product
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 { | |
$image_src = 'https://placehold.it/150x30/'; | |
} | |
$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