Skip to content

Instantly share code, notes, and snippets.

@wpserve
Last active December 6, 2022 08:13
Show Gist options
  • Save wpserve/e80ea9aaf978dfedb11edb44d2739dce to your computer and use it in GitHub Desktop.
Save wpserve/e80ea9aaf978dfedb11edb44d2739dce to your computer and use it in GitHub Desktop.
<?php
// Checkbox filters brand images
add_filter( 'wpc_filters_checkbox_term_html', 'wpc_term_brand_custom_logo', 10, 4 );
// Radio filters brand images
add_filter( 'wpc_filters_radio_term_html', 'wpc_term_brand_custom_logo', 10, 4 );
function wpc_term_brand_custom_logo($html, $link_attributes, $term, $filter)
{
$img = '';
// Desired taxonomy 'pa_brand'
if( $filter['e_name'] !== 'pa_brand' ){
return $html;
}
if( ! isset( $term->slug ) ){
return $html;
}
// Term meta key 'image' that conitains term image src
$src = get_term_meta($term->term_id, 'image', true);
if( $src ){
$img = '<span class="wpc-term-image-wrapper"><span class="wpc-term-image-container" style="background-image: url('.$src.')"></span></span>';
$html = '<a '.$link_attributes.'>'.$img . ' '. $term->name.'</a>';
}
return $html;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment