checkout.js
34 lines
| 1 | function setAmeliaFieldValue(selector, value) { |
| 2 | let element = document.querySelector(selector); |
| 3 | |
| 4 | if (typeof element !== 'undefined' && element) { |
| 5 | const valueSetter = Object.getOwnPropertyDescriptor(element, 'value').set; |
| 6 | const prototype = Object.getPrototypeOf(element); |
| 7 | const prototypeValueSetter = Object.getOwnPropertyDescriptor(prototype, 'value').set; |
| 8 | |
| 9 | if (valueSetter && valueSetter !== prototypeValueSetter) { |
| 10 | prototypeValueSetter.call(element, value); |
| 11 | } else { |
| 12 | valueSetter.call(element, value); |
| 13 | } |
| 14 | |
| 15 | element.dispatchEvent(new Event('input', { bubbles: true })); |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | document.addEventListener('DOMContentLoaded', function() { |
| 20 | if ('ameliaCustomer' in window) { |
| 21 | let ameliaCustomerInterval = setInterval( |
| 22 | function () { |
| 23 | if (document.body.classList.contains('woocommerce-checkout')) { |
| 24 | clearInterval(ameliaCustomerInterval); |
| 25 | |
| 26 | Object.keys(ameliaCustomer).forEach((key) => { |
| 27 | setAmeliaFieldValue('#' + key, ameliaCustomer[key]); |
| 28 | }) |
| 29 | } |
| 30 | }, 500 |
| 31 | ) |
| 32 | } |
| 33 | }); |
| 34 |