Jump to content

How to show Price only if user is Logged In?


Recommended Posts

Hi, there is 2 options:

Add this code to the bottom of config/config.inc.php

if ($context->cookie->isSessionAlive() ? Configuration::set('PS_CATALOG_MODE', 0) : Configuration::set('PS_CATALOG_MODE', 1));

or wrap all prices in your theme .tpl files

{if $customer.is_logged}
	<p>Display price</p>
{else}   
	<p>DO NOT Display price</p>
{/if}

 

Link to comment
Share on other sites

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:

image.thumb.png.3af20980480577a11647628c2fdd1fc3.png

 

image.thumb.png.25eabba8eb93157819c997e78d2148e1.png

 

The result when the visitor is not logged in:

image.thumb.png.d28a961b1c3b27db8b11e3bb7286d3e2.png

 

When the customer is logged in:

image.thumb.png.46cc293fc41d09ce9d3f7c630c0e4027.png

 

 

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"

image.thumb.png.337ec34089d68dea5e983984b70f7f45.png

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:

image.thumb.png.2c67bf9190fe705031dbc1489dfe2305.png

 

And what customers (logged in) will see:

image.thumb.png.2fcf30766996e16dffc6b8fc0208401b.png

 

All of this with no need to edit codes, just with some configurations.

I hope it helps.

 

image.png

Edited by AmirRzd (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...