I am trying to achieve the following: 1> Hide Price Field for a Role only on a specific content type.

I am using Drupal Commerce.

Things I tried: 1> Field Permissions for the commerce_price field on a product. But because we using the same field across all product types the settings do not apply to just 1 product type.

2> preprocess_node But could not access the price componenet. As it is a component inside the product reference field.

Could you please help me figure this out. Any help would be really appreciated!!

Links referred: https://www.drupal.org/node/1496450 Is there a way to hide the price on a product using Drupal Commerce?


I have never used Drupal Commerce, however I understand that you want to hide a field according to a role. That is doable through hook_field_access().

hook_field_access($op, $field, $entity_type, $entity, $account)

Determine whether the user has access to a given field. This hook is invoked from field_access() to let modules block access to operations on fields. If no module returns FALSE, the operation is allowed.


  • Thank you for the quick revert. I really appreciate that. As i would also need the node type information..I should include this function inside of node alter hook or pre process node hook right ? – user3570925 Mar 26 '15 at 17:03
  • Which function?The hook_field_access()? The field is attached to an entity, which is passed as input in the hook_field_access, so you can check info through $entity and $entity_type. More info are included in the hook's documentation. – Potney Switters Mar 27 '15 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.