Notice: Undefined property: stdClass::$field imce drupal
The global $user object is not guaranteed to have all the fields loaded onto it.

Try specifically loading the user like this:

global $user;
// Load the full user object.
$account = user_load($user-&gt;uid);
// Get the user code.
$code = '';
if ($items = field_get_items('user', $account, 'field_code')) {
  $code = $items[0]['value'];
}
return $code;