wp_login overriding user meta data
Question
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 (){
if(is_page('installation')){
woocommerce_form_field(
'serial_login',//CHANGE HERE
array(
'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);
0
2 years
2020-12-22T18:10:20-05:00
2020-12-22T18:10:20-05:00 0 Answers
7 views
0
Leave an answer