namhost Posted September 5, 2019 Share Posted September 5, 2019 I am trying to find a hook that will allow me to alter the company name BEFORE it is sent for registration. For example, if the user's company name is: ABC INC [[123]] I want to modify it, so that it is only: ABC INC Another billing module I use unfortunately requires that I modify the user's company name to include his user id in this way. But I don't want that user id portion to appear on whois records. So I want to modify it before it is sent off for registration. I have started browsing though these: https://developers.whmcs.com/hooks-reference/domain/ ... but perhaps someone else can steer me in the right direction? 0 Quote Link to comment Share on other sites More sharing options...
string Posted September 5, 2019 Share Posted September 5, 2019 As far i see, the hooks can not be used to override the contact details. A possible workaround would be that you change the clients company name via the hooks PreDomainRegister / PreDomainTransfer and then restore over the hooks AfterRegistrarRegister / AfterRegistrarTransfer. Not the nicest solution, there are probably better ways. 0 Quote Link to comment Share on other sites More sharing options...
namhost Posted September 9, 2019 Author Share Posted September 9, 2019 For anyone that might be interested: <?php if (!defined("WHMCS")) die("This file cannot be accessed directly"); use WHMCS\ClientArea; use WHMCS\Database\Capsule; /* * Before registering a domain name, this will change the company name * from: * ABC INC [[123]] * to: * ABC INC * i.e. Removes the [[123]] */ add_hook('PreRegistrarRegisterDomain', 1, function($vars) { if (!empty($vars['params']['userid'])) { $userid = $vars['params']['userid']; $client = Capsule::table('tblclients') ->where('id', $userid) ->first(); if (!empty($client->companyname)) { if (strpos($client->companyname, '[[') !== false && strpos($client->companyname, ']]') !== false) { $newName = $client->companyname; $newName = substr($newName, 0, strpos($newName, '[[')); $newName = trim($newName); Capsule::table('tblclients') ->where('id', $userid) ->update([ 'companyname' => $newName, ]); } } } }); add_hook('AfterRegistrarRegister', 1, function($vars) { if (!empty($vars['params']['userid'])) { $userid = $vars['params']['userid']; $client = Capsule::table('tblclients') ->where('id', $userid) ->first(); if (!empty($client->companyname)) { if (strpos($client->companyname, '[[') !== false && strpos($client->companyname, ']]') !== false) { // name already contains [[]] } else { $newName = $client->companyname; $newName = $newName.' [['.$userid.']]'; $newName = trim($newName); Capsule::table('tblclients') ->where('id', $userid) ->update([ 'companyname' => $newName, ]); } } } }); 1 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.