BuddyDev

Search

Replies

  • Participant
    Level: Initiated
    Posts: 4
    Curious on #47047

    Hello Sir,
    You are such a light. Your willing answers, gave me the courage to try reaching out in other places.

    This seemed to have paid off, in about 90% of my need. This code below has actually achieved what I want:

    `function createCustomUserId($user)
    {
    $user_id = intval($user->data->ID);
    $id_prefix = ‘pie’;
    $separator = ‘-‘;
    $number_format = ‘000’;
    $batch_symbol = ‘BN’;
    $batch_number = ‘1’;

    $custom_id = $id_prefix . $separator . $number_format . $user_id . ‘ | ‘ . $batch_symbol . $batch_number;

    update_user_meta( $user_id, ‘custom_user_id’, $custom_id);
    }
    add_action( ‘pie_register_after_user_created’ , ‘createCustomUserId’, 10, 1);

    function showCustomUserId()
    {
    $output = ”;

    if ( is_user_logged_in() )
    {
    $user_id = get_current_user_id();
    $custom_id = get_user_meta( $user_id , “custom_user_id” , true);

    $output .= ‘<div class=”custom_id_div”>’;
    $output .= ‘<p>’;
    $output .= $custom_id;
    $output .= ‘</p>’;
    $output .= ‘</div>’;

    return $output;
    }
    }
    add_shortcode( ‘custom_user_id’, ‘showCustomUserId’ ); `

    =======================
    And it produced something like this—- https://imgur.com/ONnbaIF

    Now, I have gone through the Code, and I believe that the Batch Range Logic is still missing from the Code.

    Since this code has done 90% the job of what I’m looking for. All I need from you now, is to help provide me the few additional lines of code into this code, that will provide for the Batch Range Logic.

    Meaning that, I am saying– You should please help me rewrite this code above, and add into it, the part that helps the code to check if the number has hit 10,000.

    Then when it is 10,001, it should assign 1 as the number of the 10,001 person, then increase the Batch Number from BN1 to BN2.

    On every 10,000, the Batch Number(BN) should increase sequentially from 1 to 2 to 3, to 4,5,6, on and on and on like that.

    This Batch Range Logic is what I believe is till missing from the code above. And I am hoping you can help me add it in.

    Needing to hear from you soon.

    Regards.

  • Participant
    Level: Initiated
    Posts: 4
    Curious on #47030

    Oh my goodness, You are heaven sent.

    Now, I will like us to imagine 2 scenarios— a scenario where there will be no WooCommerce on the website.

    And a second scenario where there will be WooCommerce on the website.

    SCENARIO ONE:
    This is a School Alumni Website– where there’s no payment for anything. Past students just register and create Account.

    Then a Unique ID is generated for them, to be shown on their Profile Page.

    SCENARIO TWO:
    A Laundry Business wants its customers to Register through WooCommerce My-Account Page.

    Then when the Customers have submitted their clothes to the Laundry Business for washing, the Unique ID is the Reference number that the Customer quotes to the company, in order to look for their Clothes. As you can see here– https://prnt.sc/o07lm-UVtkFa

    These are the Two Scenarios. The Numbering Prefix would be different, but the Logic is the same.

    Meaning that, for the Alumni Website, the Prefix is “STN” for Student Number. While for the Laundry Business, the Prefix is “Tag Number”.

    Here is the Numbering Logic:

    Prefix, then number counts from 1 to infinity.

    By the Time we get to the One Millionth Member, the number will be STN-1,000,000.

    By the 1 Bilionth Member, the Number will be too long. So I imagined Batch Number Range– the method of splitting the Site Members or Users into smaller units called “Batches”.

    So, if I set 10,000 as the Batch Range. It means that when I hit Ten Thousand, the Number will be STN-10,000-BN1– with BN1 representing Batch Number 1.

    When the number is 10,001, this one additional person will fall into Batch2, and his Unique ID will be STN-1-BN2.

    This is the Numbering Logic. And I do hope you understand?

    Special Regards.

  • Participant
    Level: Initiated
    Posts: 4
    Curious on #47025

    Your reply did make my day.Your reply made me very happy.

    Even though it has not provided my solution, it did give me hope somehow that there could be a light at the end of the tunnel.

    Now, I want the IDs to be automatically generated. See here– https://wordpress.stackexchange.com/questions/65738/create-unique-id-for-user

    Somehow, I believe that a Code from that website could be a Key. I mean this Code below:

    
    add_filter("user_register", "get_unique");
    function get_unique($user_id){
        $prefix = "PAY-";
        do {
            $unique = mt_rand();
            $unique = substr($unique, 0, 3);
            $unique = $prefix . $unique;
        } while (!check_unique($unique));
        return update_usermeta( $user_id, 'memnumber', $unique );//$unique;
    }
    function check_unique($unique) {
        global $wpdb;
        $result = $wpdb->get_var("SELECT meta_value from $wpdb->usermeta where meta_key='memnumber' AND meta_value = '$unique'");
        if(empty($result))
            return true;
        return false;
    }
    

    ============================================================

    The challenge is that I don’t know PHP. I only know how to insert PHP Code Snippets into my Child Theme’s Functions.PHP file.

    Instinctively, I feel that my answer is somewhere in that code.

    QUESTION 1:
    Can you Please help me look to that Page, and look at the Codes there, to see if they can provide my solution?

    My Point is that, what I am looking for, is not impossible. I’ve just not found it yet, in WordPress.

    So, can you Please help me take a look here– https://wordpress.stackexchange.com/questions/65738/create-unique-id-for-user

    —- to see how that Page could provide solution for me?

    Needing to hear from you soon.

    Regards.