Hide price for anonymous user

I have looked absolutely everywhere. Has anyone been able to find a way to hide pricing for users (not logged in)not able to see the price. Upon login the prices would appear. I want to be able to have people see what products i offer but not pricing. Once i give them access to the site they will have appropriate pricing based on roles. Any help would be greatly appreciated.

Posted: Apr 4, 2012


dspock on April 4, 2012

Thank you for the quick response. That helped with one other issue i am having. But, for the price issue it states that the field is locked. Any ideas how to get around this part now?

mwisner on April 4, 2012

Ohh man, I didn't even think about that. I'm used to the content permissions all being placed on the permissions page...

Here is a relevant core issue by Ryan himself... http://drupal.org/node/806102 it looks like there are a few people are having the same issue.

I can't think of anyway to "unlock" the field besides going into the database and manually changing the setting... which I really do not recommend doing.

dspock on April 4, 2012

Again thanks for the direction. Unfortunately i would almost be willing to go the route of editing the database but i would have absolutely no idea what table that would be in. The risk is almost worth trying to get past this.

dannyd on April 14, 2012

I found that "commerce_price.module" file has 'locked' => TRUE value so i try to modify it to FALSE.
I do in a clean kickstart install, then i add field_permissions module and it let to show only for register users.
Then i found that you have to hide the "add to cart" to anonymous also in order to complete hide prices to anonymous users (and made your site works as catalog for anonymous). For this, go to your product display field product (the one that references the products) and made it visible only to register users.

I don't know how bad it's this solution but it's the only one that works. Now i'm searching a solution for a site with products without losing them...

can any core member test about this? or explain us a little more about why it must be locked by default

dannyd on April 14, 2012

I found another solution (cleaner) after spent some hours trying crazy things
I also found that it's not actual solution for exporting from drupal commerce. Importing is easy if you have a good cvs created using feeds but i can't find a solution for exporting actual products.

For unlock price you can go to your database -> table field_config -> edit commerce_price entry to change "locked" from 1 (enabled) to 0 (disabled)

Then you can have your field price unlock for edit it and use field permissions module to made it hide to anonymous users.

Also you can lock it again after doing the change!!.
Please D8 developers, add this kind of permisions in core! :P

dannyd on April 18, 2012

You are wellcome, i tried on a local install and live and i have no problems (i lock it again) and do the job we need.

astutonet on December 16, 2012

I'm right in the middle of a project.

I want to prevent anonymous users can not see the price and they also can not make purchases on the site without being logged.

In the solution above, if the user clicks in "Add to cart", he can still see the price on the "Shopping Cart", which I also do not want.

The idea is to get the site to work only as a gallery for anonymous users. Send the user to the login screen when they click buy is a good idea.

Anyone have any solution?

Thank you.

vivien on April 9, 2013

genius! thanks! almost missed out the part on the fields permissions module -.-

newbieuser on October 9, 2013

could u elaborate on how to " go to your database -> table field_config -> edit commerce_price entry to change "locked" from 1 (enabled) to 0 (disabled)".

SoftService on January 29, 2013

I tried all of the above.
Add To Cart is now hidden for anonymous users in the product display node and in teaser view, so that's OK.
However, the price is only hidden in the view, because I used the product reference twice. First showed as rendered and the second as Add To Cart. In both cases, the fields are coming from the product type, where I could set custom permissions on the fields.
But on the product display node, you have only the product reference, which i'm showing with the Add to cart display form widget. It's hidden for anonymous users because of the custom permissions in the product type.
The price is an extra 'field' that's unknown in the nodes field collection, but shows up on the Manage Display form of the node. And there I have no possibility to format the field, and it doesn't follow the field permission setting of the product type.

I tried to hide the field using a module, but i cannot find the correct $node->content field name for the commerce_price.


SoftService on January 29, 2013

I tried this module, but it only hides the Add to cart button and quantity field. The price is still displayed.

function hook_node_view($node, $view_mode) {
$node->content['field_product']['#access'] = FALSE;

Any help to find the right field to hide the price would be appreciated.

SoftService on January 30, 2013

After digging in deeper, I found the field that I need, but I don't know how to access it to hide it.

I should be the field product:commerce.
I tried:
$node->content['product:commerce_price']['#access'] = FALSE;
$product->commerce_price['#access'] = FALSE;

I'm not getting any errors, but the price is never hidden.

Please help me to solve this.

newbieuser on March 9, 2013

for my purposes, price is visible to everyone, only trade have access to shopping cart.
so I just "hidden" add to cart, from content type, manage display.
How to show shopping cart again, when registered trade login?
By rules?
I am new user, not developer, not programmer, need step by step instruction pls.