As mentioned in PrestaShop customer group section:
PrestaShop has three default customer groups:
- Visitor - All persons without a customer account or customers that are not logged in.
- Guest - All persons who placed an order through Guest Checkout.
- Customer - All persons who created an account on this site. [and logged in]
So PrestaShop can determine if a customer is logged in or not with this built-in feature. No coding needed.
So to hide prices for not logged in visitors, simply:
- Go to Shop Parameters > Customer Settings > Groups (tab)
- Edit "Visitor" group
- Set "Show prices" to "NO"
- Save
Like the image below:
The result when the visitor is not logged in:
When the customer is logged in:
The following instruction is optional:
Now if you want to inform your visitors/customers that they need to login to see the prices depending on your theme you can set a banner or a text block informing them and make that module hidden for "Customer" group.
In the default classic theme:
- Go to Design > Position and click on the "Transplant a module" blue button
- In the "Module" field search for "Custom Text Block" or "Banner"
- In the "Transplant to" field search for "displayTop" or any other hook you prefer.
- Click on "Save"
Now you need to create a proper content (an HTML Text or a Banner). I explain the Custom text module:
- Go to Modules > Module Manager
- Search for "Custom Text Block"
- Enable it if it is disabled and then click "Configure"
- Provide a proper information for visitors (Not logged in users). For example: "To see the prices, please login to your account. If you do not have an account you can create a new one here." And you can link the words to the log in page.
- Save
Then you need to hide this block for logged in customers:
- Go to Shop Parameters > Customer Settings > Groups (tab)
- Edit "Customer" group
- In the "Authorized modules" section, set the "Custom Text Block" module to "NO"
- Save
Now what visitors (not logged in) will see:
And what customers (logged in) will see:
All of this with no need to edit codes, just with some configurations.
I hope it helps.