Currency switcher by realmag777 - Compatible

Ensure compatibility with the Currency Switcher plugin by realmag777.

function awdrGetWCSCurrencyRate(){
    global $WOOCS;
    $current_currency_rate = 1;
    if(isset($WOOCS)) {
        if (is_object($WOOCS) && method_exists($WOOCS, 'get_currencies')) {
            $currencies = $WOOCS->get_currencies();
            $convert_to_current_currency = false;
            if (isset($WOOCS->is_geoip_manipulation) && $WOOCS->is_geoip_manipulation) {
                $convert_to_current_currency = true;
            }
            if (isset($WOOCS->is_multiple_allowed) && $WOOCS->is_multiple_allowed) {
                $convert_to_current_currency = true;
            }
            if (isset($WOOCS->woocs_is_fixed_enabled) && $WOOCS->woocs_is_fixed_enabled) {
                $convert_to_current_currency = true;
            }
            if ($convert_to_current_currency === true) {
                if (isset($currencies[$WOOCS->current_currency]) && isset($currencies[$WOOCS->current_currency]['rate'])) {
                    if ($currencies[$WOOCS->current_currency]['rate'] != 0) {
                        $current_currency_rate = $currencies[$WOOCS->current_currency]['rate'];
                    }
                }
            }
        }
    }
    return $current_currency_rate;
}


add_filter('advanced_woo_discount_rules_discounted_price_of_cart_item', function ($price, $cart_item, $cart_object, $discount_prices) {

    $current_currency_rate = awdrGetWCSCurrencyRate();
    if(isset($current_currency_rate) && !empty($current_currency_rate)){
        $price = $price / $current_currency_rate;
    }
    return $price;
} , 10, 4);

add_filter('advanced_woo_discount_rules_converted_currency_value', function ($value,$type) {
    $current_currency_rate = awdrGetWCSCurrencyRate();
    if(isset($current_currency_rate) && !empty($current_currency_rate)){
        $value = $value * $current_currency_rate;
    }
    return $value;
} , 10, 2);