| 1 |
/** |
| 2 |
* Woo Checkout Place Order widget behaviour. |
| 3 |
* |
| 4 |
* The button carries form="checkout", but WooCommerce's checkout form has no |
| 5 |
* id - only name="checkout" and class="checkout". An unresolvable form |
| 6 |
* attribute makes a submit button inert, so a button placed outside the form |
| 7 |
* did nothing at all. Give the form an id and point the buttons at it. |
| 8 |
*/ |
| 9 |
(function () { |
| 10 |
'use strict'; |
| 11 |
|
| 12 |
const FORM_ID = 'ka-woo-checkout-form'; |
| 13 |
|
| 14 |
const attach = () => { |
| 15 |
const buttons = document.querySelectorAll('.ka-woo-checkout-place-order__btn'); |
| 16 |
if (!buttons.length) { |
| 17 |
return; |
| 18 |
} |
| 19 |
|
| 20 |
const form = document.querySelector('form.woocommerce-checkout, form.checkout[name="checkout"]'); |
| 21 |
if (!form) { |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
if (!form.id) { |
| 26 |
form.id = FORM_ID; |
| 27 |
} |
| 28 |
|
| 29 |
buttons.forEach((button) => { |
| 30 |
if (button.form === form) { |
| 31 |
return; |
| 32 |
} |
| 33 |
button.setAttribute('form', form.id); |
| 34 |
}); |
| 35 |
}; |
| 36 |
|
| 37 |
document.addEventListener('DOMContentLoaded', attach); |
| 38 |
|
| 39 |
// The checkout markup is re-rendered on every update_order_review call. |
| 40 |
if (window.jQuery) { |
| 41 |
window.jQuery(document.body).on('updated_checkout', attach); |
| 42 |
} |
| 43 |
|
| 44 |
if (window.elementorFrontend && window.elementorFrontend.hooks) { |
| 45 |
window.elementorFrontend.hooks.addAction('frontend/element_ready/woo_checkout_place_order.default', attach); |
| 46 |
} |
| 47 |
})(); |
| 48 |
|