Support

Account

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

  • I suggest you look at do_action( ‘user_register’, int $user_id, array $userdata )

    Which fires immediately after a new user is registered.

    So as an example (code untested), you could look at something like:

    <?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, 'your_acf_field_name', $randomise );
     
    }

    You need to setup the ACF field and link it to the user role(s). You then need to update the above example with the field name.
    Add the code to your function file and test it.
    If it doesn’t work, look to try and debug why.