FacetWP – support ACF Country field type

<?php

/* Add to your child theme's functions.php */

// Replace the country code with the name
add_filter( 'facetwp_acf_display_value', function( $value, $params ) {
    if ( 'country' == $params['facet_name'] ) {
        $post_id = (int) $params['post_id'];
        $country_code = $params['facet_value'];
        $country_field_object = get_field_object( 'country', $post_id );
        $countries = $country_field_object['choices'];
        return $countries[ $value ];
    }
    return $value;
}, 10, 2 );