facetwp hash for colors

djrmom

{{gist file=”custom-hooks.php” lang=”php”}}
//filter color display to maybe add hash to hex colors
add_filter( ‘facetwp_facet_render_args’, function( $args ) {
if ( ‘colors’ == $args[‘facet’][‘name’] ) {
foreach ( $args[‘values’] AS $key => $value ) {
$args[‘values’][$key][‘facet_display_value’] = ( ” != ( $color = sanitize_hex_color_no_hash( $value[‘facet_display_value’] ) ) ) ? ‘#’ . $color : $value[‘facet_display_value’];
}
}
return $args;
});

//filter color index to maybe add hash to hex colors
add_filter( ‘facetwp_index_row’, function( $params ) {
if ( ‘colors’ == $params[‘facet_name’] ) {
$display_value = $params[‘facet_display_value’];
$params[‘facet_display_value’] = ( ” != ( $color = sanitize_hex_color_no_hash( $params[‘facet_display_value’] ) ) ) ? ‘#’ . $color : $params[‘facet_display_value’];
}
return $params;
}, 10 );
{{/gist}}