wp_login overriding user meta data


I added a serial number field to the woocommerce wordpress login on CERTAIN PAGES so when a user logs in the meta data gets updated which works great. But when the user logins to a page that doesn’t ask for the serial number field the data gets deleted. I have tried writting a function that will only execute once but that doesn’t seem to be working.

    add_action( 'woocommerce_login_form', 'woocom_extra_register_fields');

function woocom_extra_register_fields (){

            'serial_login',//CHANGE HERE
                'type'        => 'text',
                'required'    => true, // just adds an "*"
                'label'       => 'Product ID: ',
            ( isset($_POST['serial_login']) ? $_POST['serial_login'] : '' )//CHANGE HERE


     function login_serial_number( $user_login, $user ) { 

                             $result = false;

                            if (!$result){
                                update_user_meta($user->ID, 'serial_login',  $_POST['serial_login']);

                                $result = true;
            add_action('wp_login', 'login_serial_number', 10, 2);
Alex Lytle 1 month 0 Answers 7 views 0

Leave an answer