Jump to content

Altering the Company Name before a domain registration?


namhost

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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,
          ]);


      }
    }
  }

});

 

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