Jump to content

Domain prices Auto-Recalculation daily


Recommended Posts

hello guys,

I'd like to run domain re-calculation on a daily basis so clients moving between categories will get their domain prices from their respective price slabs.

Anyone can share a piece of code for this or can code it for a small fee?

 

thanks,

Justin

Link to comment
Share on other sites

Here is a hook that should do what you need:

 

<?php

/*
* Hook to automatically recalculate pricing for domains after daily cron is ran
*/

if (!defined("WHMCS"))
die("This file cannot be accessed directly");

use WHMCS\Database\Capsule;

add_hook('DailyCronJob', 1, function($vars)
{
    logActivity('Starting autorecalculate for domains	', 0);
    $adminUsername = ''; // Optional for WHMCS 7.2 and later
    

    foreach (Capsule::table('tbldomains')->pluck('id') as $v)
    {
        localAPI('UpdateClientDomain', array('domainid' => $v, 'autorecalc' => true), $adminUsername);
    }
    logActivity('Ending autorecalculate for domains	', 0);

});

 

Link to comment
Share on other sites

25 minutes ago, sweethome said:

thanks a lot man, gonna try it tomorrow in cron and see hoe it goes.

many thanks for sharing the code, this should probably be in native whmcs as a function..

 

tnx

 

Just place the code in a file and name it "autocalc.php" and upload it in your WHMCS's  "/includes/hooks/" folder and it will run during your daily cron.

Link to comment
Share on other sites

  • 3 months later...
37 minutes ago, ResellerWiz said:

I agree. Recalculating all existing service and/or domain pricing in WHMCS should already be a feature and not require an additional script or addon.

There's so much missing in WHMCS it's unbelievable for an important software like it. They don't do much effort for a giant team.

I wouldn't use daily existing products/services updates since many customers have different pricing but a feature for it would be nice on certain occasions for sure. Domains is the one where everyone pays the same, at least for us.

Link to comment
Share on other sites

  • 3 months later...
On 9/28/2023 at 9:56 AM, SimpleSonic said:

I agree. Recalculating all existing service and/or domain pricing in WHMCS should already be a feature and not require an additional script or addon.

Unfortunately, I've been noticing an issue with the hook in my WHMCS running 7.9 and 7.10.
In my other WHMCS sites running 8.4 and 8.8 it is working well, from what I can tell.

The issue is this:

In the one running WHMCS 7.9: default currency is EUR. Price of .com for now is 13.79 EUR. It is giving the domain price of EUR to the other currencies, USD, CAD. I checked my domain pricing just to make sure and they're not at 13.79, only EUR is. CAD is set to 20.27. USD to 14.92. Yet, they show as 13.79.

In the one running WHMCS 7.10: Even worse. Default currency is USD. It increased my .com price of 17.95 USD to 308 USD+. Some at 400 USD. Same for other currencies, around 300-400.

When I auto-recalculate manually in the client profile, it sets it correctly until the cron runs later on. It reverts it to the incorrect value.

Do you know why this is happening? I suspect I will have to remove the hook on those sites :(.

Should I fill in the admin username in the hook code? I did not do that for any site.

 

Link to comment
Share on other sites

40 minutes ago, Ramouz said:

Unfortunately, I've been noticing an issue with the hook in my WHMCS running 7.9 and 7.10.
In my other WHMCS sites running 8.4 and 8.8 it is working well, from what I can tell.

The issue is this:

In the one running WHMCS 7.9: default currency is EUR. Price of .com for now is 13.79 EUR. It is giving the domain price of EUR to the other currencies, USD, CAD. I checked my domain pricing just to make sure and they're not at 13.79, only EUR is. CAD is set to 20.27. USD to 14.92. Yet, they show as 13.79.

In the one running WHMCS 7.10: Even worse. Default currency is USD. It increased my .com price of 17.95 USD to 308 USD+. Some at 400 USD. Same for other currencies, around 300-400.

When I auto-recalculate manually in the client profile, it sets it correctly until the cron runs later on. It reverts it to the incorrect value.

Do you know why this is happening? I suspect I will have to remove the hook on those sites :(.

Should I fill in the admin username in the hook code? I did not do that for any site.

 

The hook was meant for v8+, so using it on older version may have unexpected results. Therefore I wouldn’t recommend it. 

Link to comment
Share on other sites

1 hour ago, SimpleSonic said:

The hook was meant for v8+, so using it on older version may have unexpected results. Therefore I wouldn’t recommend it. 

Hmm. Good thing I discovered that then. I suggest editing your post if you're able, to mention that. And, perhaps even the comment in the code since it makes us think we can use it with WHMCS 7.2+. Unless you're able to make it work with WHMCS 7.x =). Or if you can guide me in the right direction, I can check it out with someone. If not, no worries.

Link to comment
Share on other sites

46 minutes ago, Ramouz said:

Hmm. Good thing I discovered that then. I suggest editing your post if you're able, to mention that. And, perhaps even the comment in the code since it makes us think we can use it with WHMCS 7.2+. Unless you're able to make it work with WHMCS 7.x =). Or if you can guide me in the right direction, I can check it out with someone. If not, no worries.

I simply provided a hook for free that works with WHMCS v8+ for automatic recalculation of services and domains, as-is. 

If you need something different or need changes made, that would be up to you.

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.

Guest
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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • 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