PluginProbe
MailerLite – WooCommerce integration / 2.0
MailerLite – WooCommerce integration v2.0
3.1.27 3.1.25 3.1.26 3.1.24 3.1.23 3.1.22 3.1.21 3.1.20 3.1.19 3.1.18 3.1.17 3.1.16 3.1.15 1.8.7 1.8.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 All 148 releases
woo-mailerlite / public / js / public.js

public.js in MailerLite – WooCommerce integration 2.0, at public/js/public.js

68 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function(a) {
2 const email = document.querySelector('#billing_email');
3 const first_name_field = document.querySelector('#billing_first_name');
4 const last_name_field = document.querySelector('#billing_last_name');
5 const signup = document.querySelector('#woo_ml_subscribe');
6
7 if (email !== null) {
8 email.addEventListener('blur', (event) => {
9 validateMLSub();
10 });
11 }
12
13 if (first_name_field !== null) {
14 first_name_field.addEventListener('blur', (event) => {
15 if(first_name_field.value.length > 0) {
16 validateMLSub();
17 }
18 });
19 }
20
21 if (last_name_field !== null) {
22 last_name_field.addEventListener('blur', (event) => {
23 if(last_name_field.value.length > 0) {
24 validateMLSub();
25 }
26 });
27 }
28
29 if (signup !== null) {
30 signup.addEventListener('click', (event) => {
31 validateMLSub();
32 });
33 }
34
35 function validateMLSub() {
36 if(email !== null && email.value.length > 0) {
37 checkoutMLSub();
38 }
39 }
40
41 function checkoutMLSub() {
42 const accept_marketing = document.querySelector('#woo_ml_subscribe').checked;
43
44 let first_name = '';
45 let last_name = '';
46
47 if (first_name_field !== null) {
48 first_name = first_name_field.value;
49 }
50
51 if (last_name_field !== null) {
52 last_name = last_name_field.value;
53 }
54
55 jQuery.ajax({
56 url: woo_ml_public_post.ajax_url,
57 type: "post",
58 data: {
59 action: "post_woo_ml_email_cookie",
60 email: email.value,
61 signup: accept_marketing,
62 language: woo_ml_public_post.language,
63 first_name: first_name,
64 last_name: last_name,
65 }
66 })
67 }
68 });