• I try to generate a membership number for a new user when the user register. I use call hook to do that using action button from jetform builder because I use jetform builder to create registration form to add custom user meta when a user register. I use this code bellow to automatically generate membership number, but it doesn’t work and the membership number wont automatically generated. Please someone can help me with this problem. Here the hook I used.

    add_action('jet-form-builder/custom-action/generate_member_number', function ($request, $action_handler) {
        $user_id = $request['user_id'];
    
        //  Populate all used member number
        $used_member_numbers = get_users(array(
            'meta_key' => 'membership_number',
            'fields' => 'id',
        ));
    
        // If no member number is used, the first member number is 1.
        if (empty($used_member_numbers)) {
            $member_number = 1;
        } else {
            // Finds the smallest unused member number.
            $member_number = 1;
            while (in_array($member_number, $used_member_numbers)) {
                $member_number++;
            }
        }
    
        // Save the member number into user meta
        update_user_meta($user_id, 'membership_number', $member_number);
    
    }, 10, 2);
    
    • This topic was modified 1 year, 1 month ago by mtprayoga.
  • The topic ‘Call Hook to generate user membership number when a new user Register’ is closed to new replies.