← All changes
|
includes/widgets/Woo_Checkout_Payment/script.js
+26
-3
51.1.78
→
51.1.86
View file →
| @@ -17,10 +17,24 @@ | ||
| 17 | 17 | return {}; |
| 18 | 18 | } |
| 19 | 19 | }; |
| 20 | 20 | |
| 21 | + const relocateIntoCheckoutForm = (root) => { | |
| 22 | + if (!root) return; | |
| 23 | + if (window.elementorFrontend && elementorFrontend.isEditMode && elementorFrontend.isEditMode()) { | |
| 24 | + return; | |
| 25 | + } | |
| 26 | + const form = document.querySelector("form.woocommerce-checkout, form.checkout"); | |
| 27 | + if (!form) return; | |
| 28 | + const widget = root.closest(".elementor-widget-woo_checkout_payment") || root; | |
| 29 | + if (form.contains(widget)) return; | |
| 30 | + const review = form.querySelector("#order_review") || form; | |
| 31 | + review.appendChild(widget); | |
| 32 | + }; | |
| 33 | + | |
| 21 | 34 | const initAccordion = (root) => { |
| 22 | 35 | if (!root || !root.dataset) return; |
| 36 | + relocateIntoCheckoutForm(root); | |
| 23 | 37 | if (root.dataset[INIT_FLAG] === "1") return; |
| 24 | 38 | root.dataset[INIT_FLAG] = "1"; |
| 25 | 39 | |
| 26 | 40 | const isAccordion = root.dataset.kaAccordion === "true"; |
| @@ -28,9 +42,16 @@ | ||
| 28 | 42 | const buttonMap = safeParseJson(root.dataset.kaPlaceorder); |
| 29 | 43 | const descMap = safeParseJson(root.dataset.kaDescriptions); |
| 30 | 44 | |
| 31 | 45 | const methods = root.querySelectorAll('.wc_payment_method'); |
| 32 | - const placeOrder = document.querySelector('#place_order'); | |
| 46 | + // Scope to this widget first: the payment template renders its own | |
| 47 | + // #place_order, so a document-wide lookup renamed the button belonging to | |
| 48 | + // another payment widget on the page instead of this one. | |
| 49 | + const placeOrder = root.querySelector('#place_order, button[name="woocommerce_checkout_place_order"]') | |
| 50 | + || document.querySelector('#place_order'); | |
| 51 | + // Remember the stock label so switching to a gateway without a custom one | |
| 52 | + // puts it back - otherwise the first custom text stuck for every gateway. | |
| 53 | + const placeOrderDefault = placeOrder ? placeOrder.textContent : ''; | |
| 33 | 54 | |
| 34 | 55 | methods.forEach((method) => { |
| 35 | 56 | const input = method.querySelector('input.input-radio'); |
| 36 | 57 | const label = method.querySelector('label'); |
| @@ -67,10 +88,12 @@ | ||
| 67 | 88 | m.classList.remove('is-active'); |
| 68 | 89 | }); |
| 69 | 90 | desc.style.display = 'block'; |
| 70 | 91 | method.classList.add('is-active'); |
| 71 | - if (placeOrder && buttonMap && buttonMap[input.value]) { | |
| 72 | - placeOrder.textContent = buttonMap[input.value]; | |
| 92 | + if (placeOrder) { | |
| 93 | + placeOrder.textContent = (buttonMap && buttonMap[input.value]) | |
| 94 | + ? buttonMap[input.value] | |
| 95 | + : placeOrderDefault; | |
| 73 | 96 | } |
| 74 | 97 | }; |
| 75 | 98 | |
| 76 | 99 | input.addEventListener('change', toggle); |