alg_ecb_get_exchange_rate

Alg_ecb_get_exchange_rate.

Description

alg_ecb_get_exchange_rate( $currency_from, $currency_to ); 

Parameters (2)

0. $currency_from
The currency from.
1. $currency_to
The currency to.

Usage

  1. if ( !function_exists( 'alg_ecb_get_exchange_rate' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'booster-for-woocommerce/includes/functions/wcj-exchange-rates-functions.php'; 
  3.  
  4. // The currency from. 
  5. $currency_from = null; 
  6.  
  7. // The currency to. 
  8. $currency_to = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = alg_ecb_get_exchange_rate($currency_from, $currency_to); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/functions/wcj-exchange-rates-functions.php  
  1. function alg_ecb_get_exchange_rate( $currency_from, $currency_to ) { 
  2. $final_rate = false; 
  3. if ( function_exists( 'simplexml_load_file' ) ) { 
  4. $xml = simplexml_load_file( 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml' ); 
  5. if ( isset( $xml->Cube->Cube->Cube ) ) { 
  6. if ( 'EUR' === $currency_from ) { 
  7. $EUR_currency_from_rate = 1; 
  8. if ( 'EUR' === $currency_to ) { 
  9. $EUR_currency_to_rate = 1; 
  10. foreach ( $xml->Cube->Cube->Cube as $currency_rate ) { 
  11. $currency_rate = $currency_rate->attributes(); 
  12. if ( ! isset( $EUR_currency_from_rate ) && $currency_from == $currency_rate->currency ) { 
  13. $EUR_currency_from_rate = (float) $currency_rate->rate; 
  14. if ( ! isset( $EUR_currency_to_rate ) && $currency_to == $currency_rate->currency ) { 
  15. $EUR_currency_to_rate = (float) $currency_rate->rate; 
  16. if ( isset( $EUR_currency_from_rate ) && isset( $EUR_currency_to_rate ) && 0 != $EUR_currency_from_rate ) { 
  17. $final_rate = round( $EUR_currency_to_rate / $EUR_currency_from_rate, 6 ); 
  18. } else { 
  19. $final_rate = false; 
  20. return $final_rate;