1( function( $ ) { 2 3 $(document).ready( function() { 4 $('#lp-have-coupon').click(function(e) { 5 e.preventDefault(); 6 $(this).hide(); 7 $('.lp-coupon-row').show(); 8 }); 9 10 $('#lp-coupon-apply').click(function(e) { 11 e.preventDefault(); 12 applyCoupon(); 13 }); 14 15 $('#leaky-paywall-registration-next').click(function(e) { 16 $('#lp-have-coupon').hide(); 17 }); 18 19 $(window).on('load', function() { 20 21 const coupon = getUrlParam("coupon_code"); 22 23 if ( coupon ) { 24 $('#lp-have-coupon').hide(); 25 $('.lp-coupon-row').show(); 26 $('#lp-coupon-apply').trigger('click'); 27 } 28 29 }); 30 }); 31 32})( jQuery ); 33 34 function getUrlParam(param) { 35 const urlParams = new URLSearchParams(window.location.search); 36 return urlParams.get(param); 37 } 38 39 40async function applyCoupon() { 41 const codeInput = document.querySelector('#lp-coupon-code'); 42 const code = codeInput.value.trim(); 43 const levelId = document.querySelector('#level-id').value.trim(); 44 45 if (!code) return; 46 47 const formData = new FormData(); 48 formData.append('action', 'lp_apply_coupon'); 49 formData.append('nonce', lpCoupons.nonce); 50 formData.append('coupon_code', code); 51 formData.append('level_id', levelId); 52 53 const res = await fetch(lpCoupons.ajaxUrl, { 54 method: 'POST', 55 body: formData, 56 }); 57 58 const data = await res.json(); 59 60 const messageEl = document.querySelector('#lp-coupon-message'); 61 62 if (!data.success) { 63 messageEl.textContent = data.message; 64 messageEl.className = 'coupon-message error'; 65 return; 66 } 67 68 // Update UI 69 messageEl.innerHTML = data.display_message; 70 messageEl.className = 'coupon-message success'; 71 72 document.querySelector('.leaky-paywall-subscription-total').innerHTML = '<strong>Total:</strong> ' + data.new_total_text; 73 document.querySelector('.lp-coupon-row label').style.display = 'none'; 74 document.querySelector('.lp-coupon-wrap').style.display = 'none'; 75 76 // Store coupon id in a hidden input for final checkout 77 document.querySelector('#coupon-id').value = data.coupon_id; 78 79 if ( data.is_free ) { 80 document.querySelector('input[name="level_price"]').value = 0; 81 82 const paymentMethodInput = document.querySelector('input[name="payment_method"]'); 83 if (paymentMethodInput) paymentMethodInput.remove(); 84 85 const gatewayInput = document.querySelector('input[name="gateway"]'); 86 if (gatewayInput) gatewayInput.value = 'free_registration'; 87 88 const nextBtn = document.querySelector('#leaky-paywall-registration-next'); 89 if (nextBtn) nextBtn.style.display = 'none'; 90 91 // Core gateway fields 92 const pmContainer = document.querySelector('.leaky-paywall-payment-method-container'); 93 if (pmContainer) pmContainer.style.display = 'none'; 94 95 // Xendit-specific fields 96 const xenditSelector = document.querySelector('.xendit-payment-type-selector'); 97 if (xenditSelector) xenditSelector.style.display = 'none'; 98 const xenditEwallet = document.querySelector('.xendit-ewallet-options'); 99 if (xenditEwallet) xenditEwallet.style.display = 'none'; 100 101 const cardDetails = document.querySelector('.leaky-paywall-card-details'); 102 if (cardDetails) { 103 cardDetails.style.display = 'none'; 104 cardDetails.querySelectorAll('input[required], select[required]').forEach(function(el) { 105 el.removeAttribute('required'); 106 }); 107 } 108 109 const paymentContainer = document.querySelector('.leaky-paywall-registration-payment-container'); 110 if (paymentContainer) { 111 paymentContainer.style.display = 'block'; 112 const paymentHeading = paymentContainer.querySelector('h3'); 113 if (paymentHeading) paymentHeading.style.display = 'none'; 114 } 115 } 116 117 if ( data.is_trial ) { 118 document.querySelector('#coupon-id').insertAdjacentHTML('afterend', '<input type="hidden" name="is_trial" value="on">'); 119 } 120 121} 122
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.