Jump to content

Code only for logged in users


Massimo333

Recommended Posts

I need to add CSS for the logged in users, but on prestashop in the body of the logged in users there is no particular class to recall them: how can I recall the users logged in on prestashop?

 

P: S I also tried to use the following code to see if I could "catch" logged in users through jQuery, but it doesn't work for me:

jQuery('document').ready(function() {
if ($this->context->customer->isLogged()) {
	echo "Logged In";
	// Do something here
} else {
	echo "Not Logged In";
	// Do something here
}
});

 

Link to comment
Share on other sites

don't mess php and javascript code

try

jQuery('document').ready(function() {
 {if $logged}
	console.log("Logged In");
	// Do something here - in javascript
 {else}
	console.log("Not Logged In");
	// Do something here - in javascript
 {/if}
});

 

Link to comment
Share on other sites

26 minutes ago, EvaF said:

don't mess php and javascript code

try


jQuery('document').ready(function() {
 {if $logged}
	console.log("Logged In");
	// Do something here - in javascript
 {else}
	console.log("Not Logged In");
	// Do something here - in javascript
 {/if}
});

You need to assign {$logged} to java-script . If you are using separate java-script file then this code did not work . You need to assign {$logged} as java-script variable by using Media::addJsDef('logged', $logged); After that you can use logged as java-script variable

jQuery('document').ready(function() {
 if (logged)

{
    console.log("Logged In");
    // Do something here - in javascript
 }

else

{
    console.log("Not Logged In");
    // Do something here - in javascript

}
});

 

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

6 hours ago, EvaF said:

don't mess php and javascript code

try


jQuery('document').ready(function() {
 {if $logged}
	console.log("Logged In");
	// Do something here - in javascript
 {else}
	console.log("Not Logged In");
	// Do something here - in javascript
 {/if}
});

 

Thanks but doesn't work...

Link to comment
Share on other sites

  • 2 years later...

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...