PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Auto update currency on cart

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Hello, is it possible to force autoupdate currency in cart? I've trouble because my customer add to cart product formerly, but realize order now. Currency rate didn't update in cart. Can You help me?

Best.
Michał Sołtys

Hello Michał Sołtys

I'm not sure I understood you correctly.

Please describe it in more detail.

Items in the cart are always counted with current rates

I am sorry Pablo.

I forgot to overwrite address to bank tables (from http://api.nbp.pl/api/exchangerates/tables/A"mid" to http://api.nbp.pl/api/exchangerates/tables/C"ask") after update the plugin.

My mistake.

Have we got a filter or hook to overwrite addresses (see above) from file woocs_after_33.php? To change default rate adresses to custom?

Best.

MS

Hello

Please  try  to use  this  code(paste  in functions.php)

add_filter('woocs_bank_polski_table', function($a){

return"C";

});

Thanks. Is it possible to change by filter"mid" to"ask" from this code:

if (!empty($currency_data[0])) {
foreach ($currency_data[0]['rates'] as $c) {
$rates[$c['code']] = floatval($c['mid']); 
}
}

It's important for me because in table"C" (http://api.nbp.pl/api/exchangerates/tables/C) doesn't exist"mid", but here is"bid" or"ask". Best.

Hello

In  this  case please  read - https://currency-switcher.com/how-to-add-its-own-custom-currency-aggregator/

Thank You, i tried make some filter, but i did mistake. Plugin can't update rates.
My code is:

add_action('woocs_announce_aggregator', function($aggregators) {
$aggregators['nbp_table_c'] = 'NBP TABLE C';
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_after_33.php in public function get_rate()
if ($aggregator_key === 'nbp_table_c') {
$url = 'http://api.nbp.pl/api/exchangerates/tables/C'; //A,B




if (function_exists('curl_init')) {
$res = $WOOCS->file_get_contents_curl($url);
} else {
$res = file_get_contents($url);
}

$currency_data = json_decode($res, TRUE);
$rates = array();
if (!empty($currency_data[0])) {
foreach ($currency_data[0]['rates'] as $c) {
$rates[$c['code']] = floatval($c['ask']);
}
}

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

return $request;
}, 10, 2);

Hello

it looks like this link returns XML - https://c2n.me/4aUqbmq.png

To  get  rates  use - simplexml_load_string($res);  - instead of - https://c2n.me/4aUqgOn.png

and    $res->ExchangeRatesTable->Rates  to get  list  of  currencies

I make this but something go wrong:

add_action('woocs_announce_aggregator', function($aggregators) {
$aggregators['nbp_table_c'] = 'NBP TABLE C';
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_after_33.php in public function get_rate()
if ($aggregator_key === 'nbp_table_c') {
$url = 'http://api.nbp.pl/api/exchangerates/tables/C'; //A,B




if (function_exists('curl_init')) {
$res = $WOOCS->file_get_contents_curl($url);
} else {
$res = file_get_contents($url);
}

$currency_data = simplexml_load_string($res);
$rates = array();
if (!empty($currency_data[0])) {
foreach ($currency_data[0]['rates'] as $c) {
$rates[$c['code']] = floatval($c['ask']);
}
}
$request = isset($currency_data['ExchangeRatesTable'][$currency_name]) ? $currency_data['rates'][$currency_name] : 0;


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


}

return $request;
}, 10, 2);

Hello

you did it wrong

you have to work with data as simpleXML object  - https://c2n.me/4aVufuZ.png

Read  this  please - https://www.php.net/manual/en/book.simplexml.php