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.