READ FIRST: This code needs to be added at the end of the functions.php file. If you are familiar with editing functions.php, feel free to continue reading. If you haven’t done this before, adding this code in the wrong place might bring the site down and the only way to access it is by editing functions.php file again via FTP. Feel free to contact us if you need help!
If you want to manually edit a referral code for a user – maybe they want a referral code that is easier to remember – add this code to your function.php file.
add_action( 'show_user_profile', 'gens_raf_user_referral_fields' );
add_action( 'edit_user_profile', 'gens_raf_user_referral_fields' );
function gens_raf_user_referral_fields( $user )
{ ?>
<h3>Module Options</h3>
<table class="form-table">
<tr>
<th><label for="gens_referral_id">Refer a friend link</label></th>
<td>
<input id="gens_referral_id" name="gens_referral_id" type="text" value="<?php echo get_the_author_meta( 'gens_referral_id', $user->ID ); ?>" />
</td>
</tr>
</table>
<?php }
add_action( 'personal_options_update', 'save_gens_raf_user_referral_fields' );
add_action( 'edit_user_profile_update', 'save_gens_raf_user_referral_fields' );
function save_gens_raf_user_referral_fields( $user_id )
{
if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
update_usermeta( $user_id, 'gens_referral_id', $_POST['gens_referral_id'] );
}
After that, go to admin dashboard -> Users, and click on one of the users that you want to edit. Then find a Refer a Friend input field and change it there, it should look like the one in the image below. After changing, click save and that’s it.