0

Currently I have a light switch on some commerce items that make them private to users that are not logged in but they still show up when the user is logged out. Is there a way to do this? I'm continuing development for a webpage and I'm still new to craft so I am sort of lost

4

Assuming yourLightSwitchFieldHandle is labeled "Hide From Logged Out Users", something like this should work. Completely untested.

{# if the user is logged in OR they are not logged in but we don't want to hide the current product #}

{% if currentUser OR (not currentUser and not yourProduct.yourLightSwitchFieldHandle) %}
        Show Product
{% endif %}
| improve this answer | |
  • Im not sure if it is labeled "Hide From Logged Out Users" how can I check? – JustinTheeDude Jul 20 '16 at 22:36
  • 1
    It's just an example... the light switch can be either positive (Show to logged out users) or negative (Hide from logged out users) depending on how you've set things up. If it's negative, you need the not in front of yourProduct.yourLightSwitchFieldHandle. If it's positive, you don't. – Brad Bell Jul 20 '16 at 22:38
  • Oh okay for sure I'll give it a try – JustinTheeDude Jul 20 '16 at 22:39
  • Could I actually make a whole category private? – JustinTheeDude Jul 20 '16 at 23:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.