Untitled

mail@pastecode.io avatar
unknown
php
2 years ago
1.0 kB
8
Indexable
Never
add_action('woocommerce_register_form', function(){
    // Get all agents
    $agents = get_users(array(
        'meta_key'     => 'salesking_group',
        'meta_value'   => 'none',
        'meta_compare' => '!=',
    ));

    ?>
    <label>Sales Agent</label><br />
    <select name="salesking_registration_link">
        <?php foreach($agents as $user){
            $user_id = $user->ID;
            $agent_id = get_user_meta($user_id,'salesking_agentid', true);

            if (empty($agent_id)){
                $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
                $agent_id = '';
                for ($i = 0; $i < 10; $i++)
                $agent_id .= $characters[mt_rand(0, 35)];
                $agent_id = strtoupper($agent_id);
                update_user_meta($user_id,'salesking_agentid', $agent_id);
            }

            ?>
            <option value="<?php echo $agent_id; ?>"><?php echo $user->display_name; ?></option>
            <?php
        }   
        ?>
    </select><br /><br />
    <?php
});