facetwp html replace labels/choices for wmpl

djrmom

{{gist file=”custom-hooks.php” lang=”php”}}
<?php
/** find replace for wmpl sites for labels/choices in filters **/
add_filter( ‘facetwp_facet_html’, function( $output, $params ) {
if ( ‘my_facet_name’ == $params[‘facet’][‘name’] ) {
$current = ( !empty( FWP()->facet->http_params[‘lang’] ) ) ? FWP()->facet->http_params[‘lang’] : apply_filters( ‘wpml_current_language’, null );
$default = apply_filters(‘wpml_default_language’, NULL );
$replace_values = [];
$replace_values[‘nl’] = [
‘Belgium’ => ‘BelgiĆ«’,
‘Bulgaria’ => ‘Bulgarije’
];
if ( $current != $default && !empty( $replace_values[$current] ) ) {
$default_values = [];
$new_values = [];
foreach ( $replace_values[$current] AS $replace_value => $replacement ) {
$default_values[] = $replace_value;
$new_values[] = $replacement;
}
$output = str_replace( $default_values, $new_values, $output );
}
}

return $output;
}, 10, 2 );

{{/gist}}