Compatible for Multi Currency for WooCommerce by villaTheme

Support Multi Currency for WooCommerce by villaTheme.

if(!function_exists('woo_discount_rules_compatible_with_villa_theme_currency_switcher')){
    function woo_discount_rules_compatible_with_villa_theme_currency_switcher($price, $is_cart = false, $discount_type = 'percentage_discount'){
        $process_conversion = true;
        if($is_cart === true){
            if($discount_type !== 'percentage_discount'){
                $process_conversion = false;
            }
        }
        if($process_conversion){
            $class_exists = false;
            if(class_exists('WOOMULTI_CURRENCY_F_Data')){
                $setting         = new WOOMULTI_CURRENCY_F_Data();
                $class_exists = true;
            } elseif(class_exists('WOOMULTI_CURRENCY_Data')){
                $setting         = new WOOMULTI_CURRENCY_Data();
                $class_exists = true;
            }
            if($class_exists === true){
                $selected_currencies = $setting->get_list_currencies();
                $current_currency    = $setting->get_current_currency();
                if ( ! $current_currency ) {
                    return $price;
                }
                if ( $price ) {
                    $price = $price / $selected_currencies[ $current_currency ]['rate'];
                }
            }
        }

        return $price;
    }
}

add_filter('woo_discount_rules_before_apply_discount', function ($price, $product, $cart){
    return woo_discount_rules_compatible_with_villa_theme_currency_switcher($price);
}, 10, 3);

add_filter('woo_discount_rules_before_calculate_discount_from_subtotal_in_cart', function ($subtotal, $discount_type, $rule){
    return woo_discount_rules_compatible_with_villa_theme_currency_switcher($subtotal, true, $discount_type);
}, 10, 3);