Last active
October 21, 2015 19:32
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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