I want generate registration no of user but registration no should be as

  • First two digit no. should be year as - 15
  • Second two digit no. should be month as - 06
  • Third two should be Character which already assign as - SY
  • Fourth should be No as - 012

So my registration no will make as - 1506SY012

How to generate it in php code ?

Add this in functions.php

This will automatically add a custom field to a user when they register on your site with a key of: user_registration_no

 add_action('user_register', 'add_user_registration_number');
    function add_user_registration_number ($user_id) {
        $reg_number = date('y').date('m').'SY'.'0'.$user_id;
        update_user_meta($user_id, 'user_registration_no', $reg_number);
    }

This should be formatted in the way in which you specified..

  • Some kind of proper explanation would be nice. Something like how the code works and where it should be should and what it actually does :-) – Pieter Goosen Jun 22 '15 at 10:57

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.