You might find that you have a reason to hide a form on your storefront from customers who haven't registered or logged-in. If you have a secondary form that you are using to collect additional data from your registered customers (not to be confused with an edit account form), it would be understandably be important to make this form only available to your registered customers. This article shows some quick tips and tricks for how to accomplish this.
How to hide a form from guest users
1) Add a form step
Add a step to your form and name it "Login Details" or something similar. This step should contain some display fields such as a paragraph and a heading that instruct guests to login or register before gaining access to the form. It might be a good idea to provide a link to your store's login and/or registration page to make it easier for guests. See the screenshot below for an example:
2) Create a form rule
Create a form rule that uses the Customer is not logged in condition, and then add the following actions:
- Hide step [select your form step/s]. This will hide the form's input fields from guest users.
- Show step [select the "Login Details" step]. This will show the "Login Details" step for guest users.
- Hide form actions and errors. This will hide the form's buttons, making sure that only the content of "Login Details" step is shown to guest users.
See the screenshot below for an example of what this rule might look like:
And there you have it! Once your extra step and form rule are in place, your form should effectively be available to only logged-in users. If a guest on your store (who isn't logged in) happens to stumble across the page that contains your form, they might see something like this:
Questions, comments, or concerns?
Feel free to reach out to our support team via email or chat and we'll be happy to assist!