1 2jQuery(document.body).on('checkout_error', function () { 3 4 let error_count = jQuery('.woocommerce-error li').length; 5 6 let sfwp_waiting = jQuery('#waitsfwp').length; 7 8 if (error_count > 1) { 9 10 jQuery('body').trigger('update_checkout'); 11 } else if (error_count == 0) { 12 jQuery('body').find('.woocommerce-NoticeGroup-checkout').css("display", "none"); 13 let popURL = { 14 action: "popup_redirect_url", 15 }; 16 jQuery.ajax({ 17 type: 'POST', 18 url: sfwp_ajax_object.ajaxurl, 19 data: popURL, 20 // dataType: 'json', 21 beforeSend: function (xhr) { 22 jQuery('body').find('.woocommerce-NoticeGroup-checkout').css("display", "none"); 23 }, 24 success: function (response) { 25 if (response != "" && response != "no-redirection") { 26 let selected_method = jQuery('input[name=payment_method]:checked').val(); 27 jQuery("#thedialog").attr('src', response); 28 jQuery("#iframe-wrap").addClass(selected_method); 29 jQuery("#iframe-wrap").addClass("open"); 30 jQuery("body").addClass('pop-visible sfwp-popup'); 31 jQuery("body").append("<div class='sfwp-pop-bg'></div>"); 32 jQuery('body').find('.woocommerce-NoticeGroup-checkout').css("display", "none"); 33 } else { 34 jQuery('body').find('.woocommerce-NoticeGroup-checkout').css("display", "block"); 35 return false; 36 37 } 38 }, 39 error: function (e) { 40 } 41 }); 42 } 43 44 if (error_count == 0 && sfwp_waiting == 0) { 45 46 jQuery('body').trigger('update_checkout'); 47 48 } 49 50}); 51 52function setIframeAttributes() { 53 const iframes = document.querySelectorAll("iframe"); 54 iframes.forEach((iframe) => { 55 // Set the crossorigin attribute to desired value, e.g., "anonymous" 56 iframe.setAttribute("crossorigin", "anonymous"); 57 }); 58 59} 60 61 62// Custom events for checkout click 63document.addEventListener("DOMContentLoaded", () => { 64 setIframeAttributes(); 65 document.body.addEventListener("click", (event) => { 66 const button = event.target.classList.contains( 67 "wc-block-components-checkout-place-order-button" 68 ); 69 70 const buttonText = event.target.classList.contains( 71 "wc-block-components-checkout-place-order-button__text" 72 ); 73 74 if (event.target && (button || buttonText)) { 75 event.preventDefault(); 76 const customEvent = new CustomEvent("onPlaceOrderButtonClicked"); 77 window.dispatchEvent(customEvent); 78 // return false 79 } 80 81 if (event.target.tagName === "INPUT" && event.target.type === "checkbox") { 82 let checkbox = event.target; 83 // Defensive DOM checks: the layout may vary when credit card is disabled 84 const saveCardDiv = checkbox && checkbox.parentNode && checkbox.parentNode.parentNode && checkbox.parentNode.parentNode.parentNode ? checkbox.parentNode.parentNode.parentNode : null; 85 86 if (saveCardDiv && saveCardDiv.parentNode) { 87 if (!checkbox.checked) { 88 saveCardDiv.parentNode.dataset.saveCardChecked = 'unchecked'; 89 } else { 90 saveCardDiv.parentNode.dataset.saveCardChecked = 'checked'; 91 } 92 } 93 94 if (saveCardDiv) { 95 const saferpayAliasDiv = saveCardDiv.querySelector(".spgw-saferpay-alias"); 96 if (saferpayAliasDiv) { 97 if (!checkbox.checked) { 98 saferpayAliasDiv.style.display = "block"; 99 const select = saferpayAliasDiv.querySelector("select"); 100 if (select) { 101 const newOption = select.querySelector("option[value='new']"); 102 if (newOption) { 103 select.selectedIndex = Array.prototype.indexOf.call(select.options, newOption); 104 } 105 } 106 } else { 107 saferpayAliasDiv.style.display = "none"; 108 } 109 } 110 } 111 } 112 113 }); 114}); 115 116// Listener for checkout api call 117(function () { 118 if( document.body.classList.contains('woocommerce-checkout') ) { 119 const originalFetch = window.fetch; 120 121 window.fetch = async function () { 122 const response = await originalFetch.apply(this, arguments); 123 124 125 if ( 126 typeof arguments[0] === "string" && 127 arguments[0].includes("wc/store/v1/checkout") 128 ) {
129 try { 130 response 131 .clone() 132 .json() 133 .then((data) => { 134 if (data?.payment_result?.payment_status === "success") { 135 const customEvent = new CustomEvent("checkoutCompleted", { 136 detail: data, 137 }); 138 window.dispatchEvent(customEvent); 139 } 140 }); 141 } catch (error) { 142 console.error("Error parsing JSON from response:", error); 143 } 144 } 145 146 return response; 147 }; 148} 149})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.