How to manually change users referral code/link?

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 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 referral code for a user, maybe he wants some 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, 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 on the image below. After changing, hit save and thats it.

Still need help? Contact Us Contact Us