| 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 |
}); |