I’m trying to have the mailpoet optin prechecked on the checkout page.
(I want to use the automated mailpoet WooCommerce mails te send some extra category related shipping information after a couple of days)
I’m using the following JS
jQuery(document).ready(function( $ ){
$('#mailpoet_woocommerce_checkout_optin').prop('checked', true);
});
De optin is checked only for a short while (unchecked after order is refreshed on load and after a change).
Has anybody got a solution for this?
2
Answers
I don’t know if you still need the solution. But I found a solution. Just place it in a woocommerce hook.
There are JS events that are fired on the checkout page anytime something happens that would cause the order summary to be updated (new product added, address changes that affect shipping, etc). They are
update_checkout
andupdated_checkout
. In order to do this properly you need to listen for those events and also ensure that if the user manually unchecked the box after you set it for them, that it doesn’t get automatically checked again.The problem I was running into with all of the solutions like the previous two offered here is that either it would be checked on page load but then not persist if the
update_checkout
event was fired, OR even worse… the user would uncheck the box and then if theupdate_checkout
event was fired it would re-check the box for them.This is my solution…
I also created a gist for this…
https://gist.github.com/reggieofarrell/b41bc9c3ea2dc70b0236767d42e0fc6c
I realize this may not jive with GDPR rules. This is for those of us that aren’t selling in Europe though.