WHMCS - Virtualmin Username Standardization

The way I was able to get around the default WHMCS username generated (first 8 chars of domain) and create usernames consistent with my settings in Virtualmin :

Created a file named virtualmin-domain-usernames.php inside of includes/hooks/

Pasted the following content into that file :

<?php function apply_custom_username_fulldomain($vars) { $orderID = $vars['OrderID']; $result = mysql_query("SELECT * FROM tblhosting WHERE orderid=$orderID"); while ($data = mysql_fetch_array($result)) { $id = $data["id"]; // make custom $username var here based on full domain $username = $data["domain"]; $queryresult = mysql_query("UPDATE tblhosting SET username='$username' WHERE id=$id"); } } function apply_custom_username_firstpartofdomain($vars) { $orderID = $vars['OrderID']; $result = mysql_query("SELECT * FROM tblhosting WHERE orderid=$orderID"); while ($data = mysql_fetch_array($result)) { $id = $data["id"]; $domainparts = explode(".",$data["domain"]); // make custom $username var here based on first part of domain $username = $domainparts[0]; $queryresult = mysql_query("UPDATE tblhosting SET username='$username' WHERE id=$id"); } } add_hook("AfterShoppingCartCheckout",1,"apply_custom_username_firstpartofdomain"); // add_hook("AfterShoppingCartCheckout",1,"apply_custom_username_fulldomain"); ?> If you use the entire domain.TLD as the username, comment out the first add_hook line and uncomment the second.

~Jeremy

Thanks good info, thanks for sharing how you solved that!

-Eric

Did you run into the issue that WHMCS ignores the custom username you set for Virtualmin service setup, and always reverts to its default scheme?

I submitted that as a bug report to the WHMCS people and received a corrected “virtualmin.php” file for use in WHMCS, which fixed the issue for me.

If you’re interested, I can send you that file. :slight_smile: