Jump to content

Price change based on secondary currency

Recommended Posts



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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
                       ->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.");


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated