mroxidane Posted November 26, 2023 Share Posted November 26, 2023 Hello, WHMCS currently have an option to update all other currencies based on the exchange rate of primary currency. However I would like to update Primary currency prices based on the secondary currency. Is it possible? Let me explain my problem in detail, I have set up my WHMCS with my local currency as main currency, but our local currency rates are not stable. We're having to change all product prices (of main & secondary currency) manually. So this is the issue from our end. I tried to change the base currency with many methods but ultimately failed as it throws several errors in the billing syste. So currently we would like to keep everything how it's, no problem. Just the price update feature is needed. So we can keep the second currency price as default and update the primary product price automatically. 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted November 27, 2023 Share Posted November 27, 2023 actually ,I think you just need to bulid a hook to update every day currency exchange price le't keep going with how WHMCS works WHMCS will automatic daily update products price in all currencies expect the main currency , so what you actually need to do is just bulid a hook update currency exchange rate for all currency based on the your local currency only this will solve the problem 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted November 27, 2023 Share Posted November 27, 2023 I tried to write the hook for you , it will be like this add_hook('PreCronJob', 1, function($vars) { // Your local currency as the primary currency $localCurrency = 'SYP'; // For example, Syrian Pound // Secondary currency to update $secondaryCurrency = 'USD'; // US Dollar // Fetch the exchange rate from an external source // let's consider // 1 USD = 10000 SYP $localCurrencyRate = 10000; if (isset($localCurrencyRate)) { if ($localCurrencyRate != 0) { // Calculate the reverse exchange rate for the dollar $reversedRate = 1 / $localCurrencyRate; try { // Update the exchange rate of the dollar in the system Capsule::table('tblcurrencies') ->where('code', $secondaryCurrency) ->update(['rate' => $reversedRate]); LogActivity("Updated $secondaryCurrency based on $localCurrency rate: $reversedRate"); } catch (\Exception $e) { LogActivity("Updating $secondaryCurrency based on $localCurrency rate failed. {$e->getMessage()} "); } } } else { LogActivity("Failed to fetch exchange rate for $localCurrency."); } }); 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.