Add images to radio facets

mgibbs189

{{gist file=”functions.php” lang=”php”}}
<?php

add_filter( ‘facetwp_facet_html’, function( $output, $params ) {
if ( ‘my_facet’ == $params[‘facet’][‘name’] ) {
$output = ”;
$values = (array) $params[‘values’];
$selected_values = (array) $params[‘selected_values’];
foreach ( $values as $result ){
$clean_val = esc_attr( $result );
$selected = in_array( $result[‘facet_value’], $selected_values ) ? ‘ checked’ : ”;
$selected .= ( 0 == $result[‘counter’] && ” == $selected ) ? ‘ disabled’ : ”;
$output .= ‘<div class=”facetwp-radio’ . $selected . ‘” data-value=”‘ . esc_attr( $result[‘facet_value’] ) . ‘”>’;
$output .= ‘<img src=”url_to_image/’ . $clean_val . ‘.svg” alt=”‘ . $clean_val . ‘”> ‘ . $result[‘counter’];
$output .= ‘</div>’;
}
}
return $output;
}, 10, 2 );

{{/gist}}