• Resolved remykonings28

    (@remykonings28)


    Hello, I’m looking for some help ??

    I have a two custom fields for phone and company. All works well and is visible on the account page. I like to change the company field into a non-editable field.

    The field is set to – not editable by user – in the registration form, though it seems that the custom code overwrites this setting and makes the custom field editable again for the user. I need company (bedrijf) to be not editable for the user, the same as the username is locked.

    I’ve added this to my functions.php to add the extra meta fields:

    // SHOW CUSTOM FIELDS ON ACCOUNT PAGE
    add_action('um_after_account_general', 'showUMExtraFields', 100);
    
    	function showUMExtraFields() {
    	  $id = um_user('ID');
    	  $output = '';
    	  $names = array('phone_number', 'company_name');
    
    	  $fields = array(); 
    	  foreach( $names as $name )
    		$fields[ $name ] = UM()->builtin()->get_specific_field( $name );
    	  $fields = apply_filters('um_account_secure_fields', $fields, $id);
    	  foreach( $fields as $key => $data )
    		$output .= UM()->fields()->edit_field( $key, $data );
    
    	  echo $output;
    	}
    
    add_action('um_account_pre_update_profile', 'getUMFormData', 100);
    	function getUMFormData(){
    	  $id = um_user('ID');
    	  $names = array('phone_number', 'company_name');
    
    	  foreach( $names as $name )
    		update_user_meta( $id, $name, $_POST[$name] );
    	}

    Picture of account: https://ibb.co/5Md53kP

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @remykonings28

    Try adding this code snippet:

    add_filter("um_is_field_disabled","um_101421_disable_custom_fields", 10, 2 );
    function um_101421_disable_custom_fields( $disabled, $data ){
     
        $names = array('company_name');
        if( um_is_core_page('account') ){
            if( in_array( $data['metakey'], $names ) ){
                return "disabled='disable'";
            }
        }
        
        return $disabled;
    }

    The above code will disable the Company Name field.

    Regards,

    Thank you for your help! that works great ??

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @remykonings

    Thanks for letting us know. I’m marking this as resolved now.

    Regards,

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Set custom field to non-editable’ is closed to new replies.