Replies: 0
Hi there,
We have ZAR and USD in our store. We tried the following code in the custom php code to convert ZAR to USD:
//convert “order total” and “item price” from ZAR to USD
class WOE_currency_mod {
var $rate = false;
function __construct() {
add_filter(‘woe_get_order_value_order_total’,array($this,’convert_zar_usd’), 10, 3);
add_filter(‘woe_get_order_product_value_item_price’,array($this,’convert_zar_usd’), 10, 3);
}
function convert_zar_usd($value, $order,$fieldname) {
return round( $value * $this->get_rate(), 2 );
}
function get_rate() {
if( $this->rate === false) {
$response = wp_remote_get(“http://ratesapi.io/api/latest?base=ZAR&symbols=USD”);
$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
$this->rate = $api_response[‘rates’][‘USD’];
}
return $this->rate;
}
}
new WOE_currency_mod();`
But it did not work, can you please help to solve?
Kind Regards,
Petrus