FacetWP – support “price” slider with Currency Switcher for WooCommerce

<?php

// Add to your (child) theme's functions.php

add_action( 'wp_footer', function() {
    $currency_code = alg_get_current_currency_code();
    $symbol = get_woocommerce_currency_symbol( $currency_code );
    $exchange_rate = alg_wc_cs_get_currency_exchange_rate( $currency_code );
?>
<script>
(function($) {
    $(function() {
        wp.hooks.removeAction('facetwp/set_label/slider');
        wp.hooks.addAction('facetwp/set_label/slider', function($this) {
            var symbol = '<?php echo $symbol; ?>';
            var exchange_rate = <?php echo $exchange_rate; ?>;
            var facet_name = $this.attr('data-name');
            var min = (parseFloat(FWP.settings[facet_name]['lower']) * exchange_rate);
            var max = (parseFloat(FWP.settings[facet_name]['upper']) * exchange_rate);
            var format = FWP.settings[facet_name]['format'];
            var opts = {
                decimal_separator: FWP.settings[facet_name]['decimal_separator'],
                thousands_separator: FWP.settings[facet_name]['thousands_separator']
            };

            if ( min === max ) {
                var label = symbol
                    + nummy(min).format(format, opts)
                    + FWP.settings[facet_name]['suffix'];
            }
            else {
                var label = symbol
                    + nummy(min).format(format, opts)
                    + FWP.settings[facet_name]['suffix']
                    + ' — '
                    + symbol
                    + nummy(max).format(format, opts)
                    + FWP.settings[facet_name]['suffix'];
            }
            $this.find('.facetwp-slider-label').html(label);
        });
    });

    $(document).on('facetwp-loaded', function() {
        if (!FWP.loaded) {
            wp.hooks.doAction('facetwp/set_label/slider');
        }
    });
})(jQuery);
</script>
<?php
}, 100 );