Last active
November 6, 2018 14:54
-
-
Save mgibbs189/e94183fa6bb64a0783168658a5f20a73 to your computer and use it in GitHub Desktop.
Add images to radio facets
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
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment