FOX - WooCommerce Currency Switcher Professional

How to add its own custom currency aggregator

From WOOCS version 2.3.1/1.3.1 it is possible with 2 next hooks: woocs_announce_aggregator and woocs_add_aggregator_processor in file functions.php of the current wordpress theme.

Example:

add_action('woocs_announce_aggregator', function($aggregators) {
    $aggregators['hello_world'] = 'My own aggregator';
    return $aggregators;
});

add_action('woocs_add_aggregator_processor', function($aggregator_key, $currency_name) {
    global $WOOCS;
    $request = [];

    //ratesapi.io as an example
    //see more examples in file \classes\woocs.php in public function get_rate()
    if ($aggregator_key === 'hello_world') {
        $query_url = 'https://api.ratesapi.io/api/latest?base=' . $WOOCS->default_currency . '&symbols=' . $currency_name;
        
        if (function_exists('curl_init')) {
            $res = $WOOCS->file_get_contents_curl($query_url);
        } else {
            $res = file_get_contents($query_url);
        }

        $data = json_decode($res, true);
        $request = isset($data['rates'][$currency_name]) ? $data['rates'][$currency_name] : 0;

        if (!$request) {
            $request = sprintf("no data for %s", $currency_name);
        }
    }

    return $request;
}, 10, 2);