Skip to content

Instantly share code, notes, and snippets.

@joshmiller83
Last active October 21, 2015 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshmiller83/4231957a485056cd2673 to your computer and use it in GitHub Desktop.
Save joshmiller83/4231957a485056cd2673 to your computer and use it in GitHub Desktop.
Quick example module of how to hide prices for anonymous users. This could be installed as is or could be a good starter to copy/paste into your own custom glue module.
name = View Price Permissions
description = Add a permission to view prices. Allows you to hide the price for anonymous or other roles.
core = 7.x
dependencies[] = commerce_product
<?php
/**
* Implements hook_permission().
*/
function hideprice_permission() {
return array(
'view any product price' => array(
'title' => t('View any product price')
)
);
}
/**
* Implements hook_field_access().
*/
function hideprice_field_access($op, $field, $entity_type, $entity, $account) {
if ($field['field_name'] == 'commerce_price' && $entity_type == 'commerce_product') {
return user_access('view any product price', $account);
}
return TRUE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment