1(function (window, $) { 2 "use strict"; 3 4 var Waave = (window.WaaveCompliance = 5 window.WaaveCompliance || {}); 6 7 function getEnabledMethods(config) { 8 return Array.isArray(config.enabled_methods) ? config.enabled_methods : []; 9 } 10 11 function getSelectedPaymentMethod() { 12 return $('.woocommerce-checkout input[name="payment_method"]:checked').val(); 13 } 14 15 function isWaaveCompliancePaymentMethod(config) { 16 return getEnabledMethods(config).includes(getSelectedPaymentMethod()); 17 } 18 19 function areTermsAccepted() { 20 var $terms = $(".waave-term"); 21 return !$terms.length || $(".waave-term:checked").length === $terms.length; 22 } 23 24 function validateBeforePlaceOrder(checkoutForm, config) { 25 if (!isWaaveCompliancePaymentMethod(config) || areTermsAccepted()) { 26 return true; 27 } 28 29 checkoutForm.submit_error( 30 "<ul class='woocommerce-error' role='alert'><li><a href='#waave-terms'>Please read and accept the terms and conditions to proceed with your order.</a></li></ul>", 31 ); 32 33 return false; 34 } 35 36 function syncVisibility(config) { 37 if (isWaaveCompliancePaymentMethod(config)) { 38 $(".waave-terms").show(); 39 return; 40 } 41 42 $(".waave-terms").hide(); 43 } 44 45 Waave.checkoutTerms = { 46 init: function (config) { 47 $("form.checkout").on("checkout_place_order", function (_, checkoutForm) { 48 if (!validateBeforePlaceOrder(checkoutForm, config)) { 49 return false; 50 } 51 }); 52 53 $(document.body).on("payment_method_selected", function () { 54 syncVisibility(config); 55 }); 56 57 syncVisibility(config); 58 }, 59 }; 60})(window, jQuery);
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.