That was a tricky one.
For the user meta update to happen only on first name update you will need the following.
- Create a constant that will contain the current user first name
- Check to see if the current user first name is different from the submitted user name on profile update
For the constant add the following line. I would suggest at the top of the function.php
define('USER_FIRST_NAME', get_user_meta(get_current_user_id(), 'first_name', true));
Now for the function
function can_editable_account_count( $customer_get_id ) {
if ( ! is_account_page() && ! is_user_logged_in() ) {
return;
}
// check if user submited the edit account form and if the first name field exists and has value
if (isset($_POST['account_first_name']) && !empty($_POST['account_first_name'])) {
// check if the current user name is not equal to the submited user name
if ($_POST['account_first_name'] !== USER_FIRST_NAME) {
update_user_meta($customer_get_id, 'can_editable_account', '0');
}
}
}