Tags/topics: 
1
Answers
Vote up!
0
Vote down!

How to hide checkout fields for authenticated users

I noticed that with the default settings, the email field was only shown for anonymous users, and was hidden when a user had logged in. I created a field-group, and I would like to know how to hide it in a similar fashion, so that it is only shown for anonymous users.

Asked by: c.altosax
on November 6, 2012

1 Answer

Vote up!
1
Vote down!

You will want to use hook_form_alter() and change the #access to the following for whatever fields you want to hide for anonymous:

<?php
// if anonymous, deny access
$form['field_name']['#access'] = user_is_logged_in();
?>
Josh Miller
Answer by: Josh Miller
Posted: Mar 6, 2013

Comments

Nice, Josh. But how can that code be modified to hide fields from authenticated users? Cheers Kevin

- drupalability on August 29, 2013