<p>We offer this during checkout.  </p>

<p>We use André Elvan's: <a href="https://github.com/aelvan/mailchimp-subscribe-craft" rel="nofollow noreferrer">https://github.com/aelvan/mailchimp-subscribe-craft</a></p>

<p>We implement it simply as an ajax call that happens in the background as the order is submitted for payment:</p>

<pre><code>    if ($('#subscribeMC').prop('checked')) {
        // Fire this off asynchronously and with any luck it just works...
        $.ajax({
            type: 'POST',
            url: '/actions/mailchimpSubscribe/list/Subscribe',
            data: {
                CRAFT_CSRF_TOKEN: window.csrfTokenValue,
                email: email,
                mcvars: {
                    FNAME: firstName,
                    LNAME: lastName,
                }
            }
        });
    }
</code></pre>

<p>One thing I like about our implementation is that I added a 'check if subscribed' function to the above plugin and we only show the checkbox if they're not already on the list - it's one of my pet hates when I keep seeing a newsletter box for a list I know I am already on.</p>

<pre><code>$.ajax({
    type: 'POST',
    url: '/actions/mailchimpSubscribe/list/checkIfSubscribed',
    data: {
        'CRAFT_CSRF_TOKEN': window.csrfTokenValue,
        'email': email
    },
    success: function(response) {
        //They're on the newsletter - hide the subscription form
        if (response.success) {
            $container.hide();
            $heading.hide();
        }
        //They're not on the list, bait the hook
        else {
            $container.fadeIn('fast');
            $heading.fadeIn('fast');
        }
    },
    //something went wrong, might as well show the form
    error: function(response) {
        $container.fadeIn('fast');
        $heading.fadeIn('fast');
    }
});
</code></pre>

<p>If you wanted to avoid JS/ajax, then I guess you could implement your own controller that you submit to at any point (e.g. intercept the commerce pay controller) - that first does your Mailchimp stuff and then calls the native controller using Craft's <code>runController</code>.</p>

<p>But the above JS works well and we get a bunch of newsletter subs with it every day...during subscribe checkout is by far the most effective way of increasing your mailing list we've found.  (And, please, whatever else you may do, <strong>do not</strong> implement a page covering newsletter signup popover!!)</p>

CC BY-SA 3.0
2017-06-07T11:25:32.870Z
Thanks a lot Jeremy. Obviously your solution is part of a bigger js strategy. So I've replaced the variables $container with $('#my-containter-div') eliminated the $heading variable and changed email with ''{{ cart.email }}' and also deleted the mcvars part, since I only want the email. Now I get two bad Requests in the console: jquery-1.11.1.min.js:4 POST https://mydomain.com/actions/mailchimpSubscribe/list/checkIfSubscribed 400 (Bad Request) and POST https://local.ingwerer.at/actions/mailchimpSubscribe/list/Subscribe 400 (Bad Request). Do you know what could be causing that?
outline4
CC BY-SA 3.0
2017-06-07T11:28:02.967Z
Now that I come to think of it... Maybe I have to wrap the form around my checkbox?
outline4
CC BY-SA 3.0
2017-06-16T00:30:38.227Z
Sorry I did not see these...did you get this working ok?
Jeremy Daalder
CC BY-SA 3.0
2017-06-03T23:56:23.173Z
2017-06-04T05:17:44.820Z
2017-06-04T05:17:44.820Z
Jeremy Daalder
<p>Just to follow up on this, we created a plugin that adds email addresses (+ First &amp; Last Name) to a MailChimp list whenever the user starts the process of an order:</p>

<p><a href="https://github.com/madebyshape/mailchimp-commerce" rel="nofollow noreferrer">https://github.com/madebyshape/mailchimp-commerce</a></p>

<p></p>

CC BY-SA 3.0
2017-10-16T21:08:16.477Z
2017-10-16T21:08:16.477Z
Jason Mayo
<p>Our checkout is only for registered users. </p>

<p>Ideally you'd just provide a checkbox that says: Subscribe to Mailchimp? </p>

<p>Any ideas?</p>

<plugin-craftcommerce>
Is it possible to subscribe a user to Mailchimp during checkout in Craft Commerce?
# Is it possible to subscribe a user to Mailchimp during checkout in Craft Commerce?

(Asked by: username_0 on 2017-06-03)

Our checkout is only for registered users.

Ideally you'd just provide a checkbox that says: Subscribe to Mailchimp?

Any ideas?

**Tags:** plugin-craftcommerce


---

## 2 answers

### Answer by username_1 on 2017-06-03. Score: 2

We offer this during checkout.  
We use André Elvan's: https://github.com/aelvan/mailchimp-subscribe-craft
We implement it simply as an ajax call that happens in the background as the order is submitted for payment:
    if ($('#subscribeMC').prop('checked')) {
        // Fire this off asynchronously and with any luck it just works...
        $.ajax({
            type: 'POST',
            url: '/actions/mailchimpSubscribe/list/Subscribe',
            data: {
                CRAFT_CSRF_TOKEN: window.csrfTokenValue,
                email: email,
                mcvars: {
                    FNAME: firstName,
                    LNAME: lastName,
                }
            }
        });
    }

One thing I like about our implementation is that I added a 'check if subscribed' function to the above plugin and we only show the checkbox if they're not already on the list - it's one of my pet hates when I keep seeing a newsletter box for a list I know I am already on.
$.ajax({
    type: 'POST',
    url: '/actions/mailchimpSubscribe/list/checkIfSubscribed',
    data: {
        'CRAFT_CSRF_TOKEN': window.csrfTokenValue,
        'email': email
    },
    success: function(response) {
        //They're on the newsletter - hide the subscription form
        if (response.success) {
            $container.hide();
            $heading.hide();
        }
        //They're not on the list, bait the hook
        else {
            $container.fadeIn('fast');
            $heading.fadeIn('fast');
        }
    },
    //something went wrong, might as well show the form
    error: function(response) {
        $container.fadeIn('fast');
        $heading.fadeIn('fast');
    }
});

If you wanted to avoid JS/ajax, then I guess you could implement your own controller that you submit to at any point (e.g. intercept the commerce pay controller) - that first does your Mailchimp stuff and then calls the native controller using Craft's runController.
But the above JS works well and we get a bunch of newsletter subs with it every day...during subscribe checkout is by far the most effective way of increasing your mailing list we've found.  (And, please, whatever else you may do, do not implement a page covering newsletter signup popover!!)

> **Comments:**
> **username_0**: Thanks a lot Jeremy. Obviously your solution is part of a bigger js strategy. So I've replaced the variables $container with $('#my-containter-div') eliminated the $heading variable and changed email with ''{{ cart.email }}' and also deleted the mcvars part, since I only want the email. Now I get two bad Requests in the console: jquery-1.11.1.min.js:4 POST https://mydomain.com/actions/mailchimpSubscribe/list/checkIfSubscribed 400 (Bad Request) and POST https://local.ingwerer.at/actions/mailchimpSubscribe/list/Subscribe 400 (Bad Request). Do you know what could be causing that?  
> **username_0**: Now that I come to think of it... Maybe I have to wrap the form around my checkbox?  
> **username_1**: Sorry I did not see these...did you get this working ok?  

---

### Answer by username_2 on 2017-10-16. Score: 1

Just to follow up on this, we created a plugin that adds email addresses (+ First & Last Name) to a MailChimp list whenever the user starts the process of an order:

<https://github.com/madebyshape/mailchimp-commerce>


---

