Support

Account

Home Forums ACF PRO Generate random code Reply To: Generate random code

  • Just tested and works fine

    Here’s what I did:
    1) Create an ACF text field called Random String
    2) This creates the label random_string
    3) For testing, I assigned this field to User Role is equal to All
    4) I added the below code to my functions.php file:

    <?php 
    add_action( 'user_register', 'myplugin_registration_save', 10, 1 );
    function myplugin_registration_save( $user_id ) {
     
    	####generate the random number
    
    	#get current date/time
    	$date = date('YmdH:i:s');
    
    	#randmoise
    	$randomise = ($date * 25);	
    
    	update_user_meta($user_id, 'random_string', $randomise ); #change random_string to your ACF field label!!!
     
    }

    5) I registered a new user
    6) I then clicked to edit the user, scrolled down to my new Random String field, this was the result: 50527810375

    Code and entire process tried and tested!