/**
* Aelia Currency Switcher - Force currency for legacy API calls.
*
* HOW TO USE THIS CODE
* Simply add the code to the bottom of your theme's functions.php file, and it
* will run automatically. For more information: https://www.skyverge.com/blog/add-custom-code-to-wordpress/
*
* GPL DISCLAIMER
* Because this code program is free of charge, there is no warranty for it, to the extent permitted by applicable law.
* Except when otherwise stated in writing the copyright holders and/or other parties provide the program "as is"
* without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of
* merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program
* is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
*
* Need a consultation, or assistance to customise this code? Find us on Codeable: https://aelia.co/hire_us
*/
/**
* Forces the selected currency to GBP for legacy API requests, unless another
* currency was passed via the URL.
*
* @param string selected_currency
* @return string
*/
function aelia_set_currency_for_api_calls($selected_currency) {
// Force selected currency to GBP for API calls, unless a
// currency was passed via the URL
if(empty($_GET['aelia_cs_currency'])) {
$selected_currency = 'GBP';
}
return $selected_currency;
}
/**
* Intercepts legacy API requests to force the currency to GBP, bypassing geolocation.
*
* @param string api_request
*/
add_action('woocommerce_api_request', function($api_request) {
add_filter('wc_aelia_cs_selected_currency', 'aelia_set_currency_for_api_calls', 30);
}, 10, 1);
Comments