Skip to main content

Email consent

There are two ways that a customer can consent to email marketing through the theme:


Anchor to Newsletter sign-up formNewsletter sign-up form

You can add a newsletter sign-up form to your theme with the Liquid form tag and accompanying 'customer' parameter. Inside the form, you need to include an input with the following attributes:

AttributeValue
typeemail
namecontact[email]

For example:

{% form 'customer' %}
<div className="email">
<label for="email">Email</label>
<input type="email" name="contact[email]" />
</div>

<div className="submit">
<input type="submit" value="Sign up" />
</div>
{% endform %}

When a customer signs up through this form, a customer will be created with the entered email, and the accepts_marketing attribute of the associated customer object will be set to true.

Tip

For another example of a newsletter sign-up form, you can refer to Dawn's implementation.


Anchor to Customer registration form checkboxCustomer registration form checkbox

Inside the customer register form, you can include a checkbox to allow customers to consent email marketing. This requires the following inputs to be placed inside the form:

Inputtypename
Accepts marketinghiddencustomer[accepts_marketing]
Accepts marketingcheckboxcustomer[accepts_marketing]

For example:

{% form 'create_customer' %}
{{ form.errors | default_errors }}

<div className="first-name">
<label for="first-name">First name</label>
<input type="text" name="customer[first_name]" />
</div>

<div className="last-name">
<label for="last-name">Last name</label>
<input type="text" name="customer[last_name]" />
</div>

<div className="email">
<label for="email">Email</label>
<input type="email" name="customer[email]" />
</div>

<div className="password">
<label for="password">Password</label>
<input type="password" name="customer[password]" />
</div>

<div className="accepts-marketing">
<input type="hidden" name="customer[accepts_marketing]" value="false" />

<input type="checkbox" name="customer[accepts_marketing]" />
<label for="accepts-marketing">Subscribe to email marketing</label>
</div>

<div className="submit">
<input type="submit" value="Create" />
</div>
{% endform %}
Tip

This solution requires a hidden input, as well as the checkbox input, as an unchecked box won't record a value when the form is submitted.


Was this page helpful?