Jump to content

Product hook to generate random username & password (non services)


SportsGalore

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by SportsGalore
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