Newsletter: How to hide newsletter section for subscribed customers

This customization will allow you to hide the Newsletter section on the homepage for customers who are already signed-in with an account and have also signed up for a newsletter in the past. The steps require you to add some liquid code into the file index-newsletter.liquid file.

Regular display:

After a customer has signed-in and also has accepted marketing (already signed-up for your newsletter):

How to:


Make a duplicate of your theme


Modify index-newsletter.liquid

Open the Code Editor:

From the Sections folder, open index-newsletter.liquid:

As you can see above there is also a similar file under the Snippets folder, be sure to open from the  Sections folder. 

Add the following line of code to the very beginning of the file:

{% unless customer.accepts_marketing %}


Tip: Add a couple blank lines at the top before adding that line of code. 


Look for the schema line, we will be adding a line of code above that line:

Once you've located the correct line, add the following code above it:

{% endunless %}


Save the file:

Customer testing

You can now use a test account that accepts email marketing for checking to see the change. In your customer list, if you are using a test account which you know the password for, verify if this checkbox is selected:

That indicates the account has subscribed to your newsletter. 

Sign-in with that account to test the section. Then you can uncheck that setting and test again, the newsletter section should appear even if they are signed-in.