FacetWP Price slider with Aelia Currency Switcher for WooCommerce plugin

  • April 23, 2022
  • 0
Hire Vivek Asodariya

What is the use of FacetWP plugin?

FacetWP plugin is a filter plugin. And you can use it to add filters from WooCommers. We can add cart-related, price-related, stock related filters to the website from FacetWP plugin.

What is the use of Aelia Currency Switcher for WooCommerce plugin?

With the currency Switcher Plugin, we can add currency from different countries to our website. Therefore, the country in which the website opens is automatically selected in the country’s currency website. So that the user does not need to select his own tax. The user can view the price of the product and place an order in his / her currency.

If the FacetWP price slider is not working with the Aelia Currency Switcher for WooCommerce plugin then you can use the below code.

Often the FacetWP price slider and the Aelia Currency Switcher for WooCommerce plugin do not work together and come in a price-related filter issue. When the user changes the currency, he does not change the price according to his currency in the price filter.

You can add the following code to the child theme functions.php file to fix the price filter.

<?php
add_action( 'wp_head', function() {
	global $woocommerce;
	$currency_code = get_woocommerce_currency();
	$symbol = get_woocommerce_currency_symbol( $currency_code );
	$WC_Aelia_CurrencySwitcher = AeliaWCCurrencySwitcherWC_Aelia_CurrencySwitcher::instance();
	$exchange_rate = $WC_Aelia_CurrencySwitcher->current_exchange_rate();
?>
<script>
(function($) {
    $(document).on('facetwp-loaded', function() {
        FWP.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);
        });
    });
})(jQuery);
</script>
<?php
}, 100 );

Your website and 3rd party cache need to be cleaned up once the code above is added. Because if you do not clear the catch the filter will not work properly and the issue will not be fixed.

Once the catch is cleared, open the website in a private browser and check the filter.

Leave a Reply

Your email address will not be published. Required fields are marked *