<?php
/** filter for translating facet display values which are translated
** in wpml's string translation
** works for acf fields such as a select box that has its option labels translated
** in string translation rather than post translation
**/
add_filter( 'facetwp_facet_display_value', function( $label, $params ) {
$lang = apply_filters( 'wpml_current_language', null );
$default = apply_filters( 'wpml_default_language', null );
if ( isset( FWP()->facet->http_params['lang'] ) ) {
$lang = FWP()->facet->http_params['lang'];
}
if ( $lang != $default ) {
switch ( $params['facet']['name'] ) {
case 'facet_name_one': // change 'facet_name_one' to name of facet
case 'facet_name_two': // use additional cases to combine facets that use the same domain in string translation - see screenshot https://d.pr/i/DgWa7G
return apply_filters( 'wpml_translate_single_string', $label, 'acf-field-group-2083', $label, $lang );
case 'facet_name_three': // additional case for different domain
return apply_filters( 'wpml_translate_single_string', $label, 'acf-field-group-2075', $label, $lang );
default:
return $label;
}
}
return $label;
}, 20, 2 );