SportsGalore Posted April 27, 2016 Share Posted April 27, 2016 I deal with products only, is there a way to have the system auto generate a username & password for a product? i see there is an random username/password option to do this but it only looks like it is related to a domain/service type buy option & not just a product (non service) Can a hook do this for basic product purchase also ? I need an additional random username/password generated for each product item purchased on the cart so that I can include that on the welcome email after purchase & link that with auth to use the product for each client etc can you advise please ? Thanks Nick 0 Quote Link to comment Share on other sites More sharing options...
SportsGalore Posted April 27, 2016 Author Share Posted April 27, 2016 PS I have enabled auto release and i see a random username & password below the pending invoice which is perfect, but on activate these details don't get saved on the invoice, so therefore I cannot include them on the auto welcome email or use them etc, they just seem to vanish after i manually activate the pending invoice ?? any tips or advice most welcome 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted April 27, 2016 Share Posted April 27, 2016 Use PreModuleCreate action hook to update tblhosting.username so that it looks like you want. Something like this: function RewriteUsernames($vars) { $username = "myawesomecustomusernamefollowedbyrandomnumbers".rand(10,100); $query = $mysql->prepare('UPDATE tblhosting SET username = :username WHERE id = :id'); $query->execute(array("username"=>$username, "id"=>$vars["params"]["serviceid"])); } add_hook("PreModuleCreate",1,"RewriteUsernames"); Keep in mind that my script is just an example. It will not work because I havent initialized PDO. Probably you want to use WHMCS syntax or mysqli or (don't do that) mysql to query your database. 0 Quote Link to comment Share on other sites More sharing options...
SportsGalore Posted April 27, 2016 Author Share Posted April 27, 2016 (edited) Use PreModuleCreate action hook to update tblhosting.username so that it looks like you want. Something like this: function RewriteUsernames($vars) { $username = "myawesomecustomusernamefollowedbyrandomnumbers".rand(10,100); $query = $mysql->prepare('UPDATE tblhosting SET username = :username WHERE id = :id'); $query->execute(array("username"=>$username, "id"=>$vars["params"]["serviceid"])); } add_hook("PreModuleCreate",1,"RewriteUsernames"); Keep in mind that my script is just an example. It will not work because I havent initialized PDO. Probably you want to use WHMCS syntax or mysqli or (don't do that) mysql to query your database. Hi Kian, Thanks for your help pal, I see the random generated username & password though so shouldn't the system be doing this "save/allocate" for me when i activate a pending order ? if i activate and then go into the invoice the username & password fields are blank, i use to sell "items" rather than service/hostings all i need to do is have the systems generated random username & password saved into that invoice detail for that client for that purchase when i activate, nothing else to happen etc i see i can include this if it saves via these varibles on the welcome Username {$service_username} Password {$service_password} but i'm not actually enabling a "service", i just want a per purchase random username & password for each product to save so i can use it to give to the client on welcome email for that product ordered after it goes active etc Edited April 27, 2016 by SportsGalore 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted April 28, 2016 Share Posted April 28, 2016 Then apply the same exact logic that you use to generate your custom usernames to InvoiceCreated or InvoiceCreationPreEmail action hooks to update tblinvoiceitems.description so that it always contains your username. 0 Quote Link to comment Share on other sites More sharing options...
SportsGalore Posted April 29, 2016 Author Share Posted April 29, 2016 is there a commercial script that can do this as my coding skills are not great? maybe you could quote on this post which is where i'm trying to get to if that is your expertise ? http://forums.whmcs.com/showthread.php?113371-Looking-for-a-Hook-expert-)-to-help-with-coding 0 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.