Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save greathmaster/d8f165ab9b882610ea9f0649c40d1f05 to your computer and use it in GitHub Desktop.
Save greathmaster/d8f165ab9b882610ea9f0649c40d1f05 to your computer and use it in GitHub Desktop.
Assigns a random 6 digit number for a username automatically. Two variations...the first will show the username field with number already filled, but editing is disabled. The second variations (uncomment the lines) will not show the username field at all, but will simply generate the numerical username and display it on the confirmation page.
/*
Assigns a random 6 digit number for a username automatically.
Two variations...
the first will show the username field with number already filled, but editing is disabled.
The second variations (uncomment the lines) will not show the username field at all, but will simply generate the numerical username and display it on the confirmation page.
*/
function my_pmpro_checkout_after_user_fields()
{
echo "<script>";
// echo "jQuery('#username').hide();";
// echo "jQuery('label[for=username]').hide();";
if(empty($_REQUEST['submit-checkout']))
{
echo
"//Taken from: https://stackoverflow.com/questions/1527803/generating-random-whole-numbers-in-javascript-in-a-specific-range
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var rand_num_username;
rand_num_username = getRandomInt(100000, 999999);
jQuery('#username').val(rand_num_username);
jQuery('#username').prop('readonly', true);";
}
echo "</script>";
}
add_action('pmpro_checkout_after_user_fields', 'my_pmpro_checkout_after_user_fields');
function my_pmpro_required_user_fields($pmpro_required_user_fields)
{
unset($pmpro_required_user_fields['username']);
return $pmpro_required_user_fields;
}
//add_filter('pmpro_required_user_fields', 'my_pmpro_required_user_fields');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment