1/** 2 * Define global variables so that the core plugin and 3rd party plugins can use them 3 * 4 */ 5 6// Paid Member Subscription submit buttons 7var pms_payment_buttons 8 9// Field wrappers 10var $pms_auto_renew_field 11 12// Checked Subscription 13var $pms_checked_subscription 14var $pms_checked_paygate 15 16// Unavailable gateways message 17var $pms_gateways_not_available 18 19// Text placeholder for the payment buttons while processing 20var pms_payment_button_loading_placeholder_text 21 22// Form object 23var $pms_form 24 25// WPPB Email Confirmation 26var is_pb_email_confirmation_on 27 28// Billing Fields 29var $pms_section_billing_details 30 31// Billing Fields Toggle 32var $pms_billing_toggle 33 34/** 35 * Core plugin 36 * 37 */ 38jQuery( function($) { 39 40 if( window.history.replaceState ) { 41 42 currentURL = window.location.href; 43 44 currentURL = pms_remove_query_arg( 'pmsscscd', currentURL ); 45 currentURL = pms_remove_query_arg( 'pmsscsmsg', currentURL ); 46 currentURL = pms_remove_query_arg( 'pms_gateway_payment_action', currentURL ); 47 currentURL = pms_remove_query_arg( 'pms_gateway_payment_id', currentURL ); 48 currentURL = pms_remove_query_arg( 'subscription_plan_id', currentURL ); 49 currentURL = pms_remove_query_arg( 'pms_wppb_custom_success_message', currentURL ); 50 currentURL = pms_remove_query_arg( 'redirect_to', currentURL ); 51 52 if ( currentURL != window.location.href ) 53 window.history.replaceState( null, null, currentURL ); 54 } 55 56 57 /* 58 * Strips one query argument from a given URL string 59 * 60 */ 61 function pms_remove_query_arg( key, sourceURL ) { 62 63 var rtn = sourceURL.split("?")[0], 64 param, 65 params_arr = [], 66 queryString = (sourceURL.indexOf("?") !== -1) ? sourceURL.split("?")[1] : ""; 67 68 if (queryString !== "") { 69 params_arr = queryString.split("&"); 70 for (var i = params_arr.length - 1; i >= 0; i -= 1) { 71 param = params_arr[i].split("=")[0]; 72 if (param === key) { 73 params_arr.splice(i, 1); 74 } 75 } 76 77 rtn = rtn + "?" + params_arr.join("&"); 78 79 } 80 81 if(rtn.split("?")[1] == "") { 82 rtn = rtn.split("?")[0]; 83 } 84 85 return rtn; 86 } 87 88 // Paid Member Subscriptions submit buttons 89 pms_payment_buttons = 'input[name=pms_register], ' 90 pms_payment_buttons += 'input[name=pms_new_subscription], ' 91 pms_payment_buttons += 'input[name=pms_change_subscription], ' 92 pms_payment_buttons += 'input[name=pms_upgrade_subscription], ' 93 pms_payment_buttons += 'input[name=pms_renew_subscription], ' 94 pms_payment_buttons += 'input[name=pms_confirm_retry_payment_subscription], ' 95 pms_payment_buttons += 'input[name=pms_update_payment_method], ' 96 pms_payment_buttons += '#pms-paypal-express-confirmation-form input[type="submit"], ' 97 98 // Profile Builder submit buttons 99 pms_payment_buttons += '.wppb-register-user input[name=register]' 100 101 // Subscription plans and payment gateway selectors 102 var subscription_plan_selector = 'input[name=subscription_plans]' 103 var paygate_selector = 'input.pms_pay_gate' 104 105 var settings_recurring = $('input[name="pms_default_recurring"]').val() 106 107 $pms_section_billing_details = $('.pms-section-billing-details') 108 $pms_billing_toggle = $('#pms_billing_toggle_checkbox') 109 is_pb_email_confirmation_on = $pms_section_billing_details.siblings('.pms-email-confirmation-payment-message').length > 0 ? true : false 110 111 // Field wrappers 112 $pms_auto_renew_field = jQuery( '.pms-subscription-plan-auto-renew' ) 113 114 // Checked Subscription 115 $pms_checked_subscription = jQuery( subscription_plan_selector + '[type=radio]' ).length > 0 ? jQuery( subscription_plan_selector + '[type=radio]:checked' ) : jQuery( subscription_plan_selector + '[type=hidden]' ) 116 $pms_checked_paygate = jQuery( paygate_selector + '[type=radio]' ).length > 0 ? jQuery( paygate_selector + '[type=radio]:checked' ) : jQuery( paygate_selector + '[type=hidden]' ) 117 118 // Unavailable gateways message 119 $pms_gateways_not_available = jQuery( '#pms-gateways-not-available' ) 120 121 pms_payment_button_loading_placeholder_text = $('#pms-submit-button-loading-placeholder-text').text() 122 123 /* 124 * Hide "automatically renew subscription" checkbox for manual payment gateway 125 * 126 */ 127 jQuery(document).ready( function() { 128 129 /** 130 * Set checked payment gateway when clicking on a payment gateway radio 131 * 132 */ 133 $( document ).on( 'click', paygate_selector, function() { 134 135 if( $(this).is(':checked') ) 136 $pms_checked_paygate = $(this) 137 138 // Show / hide extra payment gateway fields 139 if( $pms_checked_paygate.data('type') == 'extra_fields' ){ 140 $('.pms-paygate-extra-fields').hide() 141 $('.pms-paygate-extra-fields-' + $pms_checked_paygate.val() ).show() 142 } else 143 $('.pms-paygate-extra-fields' ).hide() 144 145 // Show billing fields 146 handle_billing_fields_display() 147 148 // Show/hide billing cycles 149 handle_billing_cycles_display( $pms_checked_paygate.val() ) 150 151 }) 152 153 154 /** 155 * Handle auto-renew checkbox and payment gateways display when clicking on a subscription plan 156 * 157 */ 158 $( document ).on( 'click', subscription_plan_selector + '[type=radio], ' + subscription_plan_selector + '[type="hidden"]', function() { 159 160 if( $(this).is(':checked') ) 161 $pms_checked_subscription = $(this) 162 163 if( typeof $pms_form == 'undefined' ) 164 $pms_form = $(this).closest('form') 165 166 handle_auto_renew_field_display() 167 handle_payment_gateways_display() 168 169 // Show billing fields 170 handle_billing_fields_display() 171 172 }) 173 174 /** Billing fields PWYW compatibility */ 175 $(document).on('change', '.pms_pwyw_pricing', handle_billing_fields_display ) 176 $(document).on('keyup', '.pms_pwyw_pricing', handle_billing_fields_display ) 177 178 /** 179 * Handle the auto renew checkbox field display in the page 180 * 181 */ 182 function handle_auto_renew_field_display() { 183 184 if ( $pms_checked_subscription.data('recurring') == 1 && $pms_checked_paygate.data('recurring') != 'undefined' ) 185 $pms_auto_renew_field.show() 186 else 187 $pms_auto_renew_field.hide() 188 189 190 if ($pms_checked_subscription.data('recurring') == 0) { 191 192 if (settings_recurring == 1) 193 $pms_auto_renew_field.show() 194 195 } 196 197 if ( ( $pms_checked_subscription.data('fixed_membership') == 'on' && $pms_checked_subscription.data('allow_renew') != 'on' ) || $pms_checked_subscription.data('recurring') == 2 || $pms_checked_subscription.data('recurring') == 3 ) { 198 $pms_auto_renew_field.hide() 199 } 200 201 if ( ( $pms_checked_subscription.data('fixed_membership') != 'on' && $pms_checked_subscription.data('duration') == 0 ) || ( $pms_checked_subscription.data('price') == 0 && !( $pms_checked_subscription.data('sign_up_fee') > 0 ) ) ) { 202 203 if ( typeof $pms_checked_subscription.data('discountedPrice') == 'undefined' ) 204 $pms_auto_renew_field.hide() 205 else if ( typeof $pms_checked_subscription.data('isFullDiscount') != 'undefined' && $pms_checked_subscription.data('isFullDiscount') == true && $pms_checked_subscription.data('discountRecurringPayments') == 1 ) 206 $pms_auto_renew_field.hide() 207 208 } 209 210 // show auto-renew checkbox for pro-rated plans that recur 211 if ( $pms_checked_subscription.data('recurring') != 'undefined' && $pms_checked_subscription.data('recurring') != 3 && $pms_checked_subscription.data('recurring') != 2 ) { 212 213 if ( $pms_checked_subscription.data('fixed_membership') != 'on' || ( $pms_checked_subscription.data('fixed_membership') == 'on' && $pms_checked_subscription.data('allow_renew') == 'on' ) ){ 214 215 if ( typeof $pms_checked_subscription.data('prorated_discount') != 'undefined' && $pms_checked_subscription.data('prorated_discount') > 0 ) 216 $pms_auto_renew_field.show() 217 218 } 219 220 } 221 222 } 223 224 225 /** 226 * Handle the payment gateways radio buttons field display in the page 227 * 228 */ 229 function handle_payment_gateways_display() { 230 231 // Before anything we display all gateways 232 $('#pms-paygates-wrapper').show() 233 $(paygate_selector).removeAttr('disabled') 234 $(paygate_selector).closest('label').show() 235 236
237 // Support for "trial" 238 if ( $.pms_plan_has_trial() ) { 239 $(paygate_selector + ':not([data-trial])').attr('disabled', true); 240 $(paygate_selector + ':not([data-trial])').closest('label').hide(); 241 242 } 243 244 245 // Support for "sign_up_fee" 246 if ( $.pms_plan_has_signup_fee() ) { 247 248 $(paygate_selector + ':not([data-sign_up_fee])').attr('disabled', true); 249 $(paygate_selector + ':not([data-sign_up_fee])').closest('label').hide(); 250 251 } 252 253 254 // Support for "recurring" 255 if ($pms_checked_subscription.data('recurring') == 2) { 256 257 $(paygate_selector + ':not([data-recurring])').attr('disabled', true); 258 $(paygate_selector + ':not([data-recurring])').closest('label').hide(); 259 260 261 } else if ($pms_checked_subscription.data('recurring') == 1) { 262 263 if ($pms_auto_renew_field.find('input[type=checkbox]').is(':checked')) { 264 $(paygate_selector + ':not([data-recurring])').attr('disabled', true); 265 $(paygate_selector + ':not([data-recurring])').closest('label').hide(); 266 } 267 268 } else if (!$pms_checked_subscription.data('recurring')) { 269 270 if (settings_recurring == 1) { 271 if ($pms_auto_renew_field.find('input[type=checkbox]').is(':checked')) { 272 $(paygate_selector + ':not([data-recurring])').attr('disabled', true); 273 $(paygate_selector + ':not([data-recurring])').closest('label').hide(); 274 } 275 } else if (settings_recurring == 2) { 276 277 $(paygate_selector + ':not([data-recurring])').attr('disabled', true); 278 $(paygate_selector + ':not([data-recurring])').closest('label').hide(); 279 280 } 281 282 } 283 284 // Pay in installments: only gateways that support billing cycles (data-billing_cycles) 285 if ( $pms_checked_subscription.length > 0 && $pms_checked_subscription.data('limit_payment_cycles') === 'yes' ) { 286 287 $(paygate_selector + ':not([data-billing_cycles])').attr('disabled', true); 288 $(paygate_selector + ':not([data-billing_cycles])').closest('label').hide(); 289 290 } 291 292 293 // Select the first first available payment gateway by default after hiding the gateways 294 if ($(paygate_selector + ':not([disabled]):checked').length == 0) 295 $(paygate_selector + ':not([disabled])').first().trigger('click'); 296 297 298 if ($(paygate_selector).length > 0) { 299 300 /** 301 * Handle case where no payment gateways are available 302 * 303 */ 304 if ($(paygate_selector + ':not([disabled])').length == 0) { 305 306 // Display the "no payment gateways are available" message 307 $pms_gateways_not_available.show(); 308 309 // Hide credit card fields 310 $('.pms-paygate-extra-fields' ).hide() 311 312 // Disable submit button 313 if ($pms_checked_subscription.data('price') != 0) { 314 315 if ($pms_checked_subscription.length != 0) 316 $(pms_payment_buttons).attr('disabled', true).addClass('pms-submit-disabled'); 317 318 } 319 320 /** 321 * Handle case where payment gateways are available for selection 322 * 323 */ 324 } else { 325 326 // Hide the "no payment gateways are available" message 327 $pms_gateways_not_available.hide(); 328 329 // Show credit card fields if the selected payment gateway supports credit cards 330 if ( $(paygate_selector + ':not([disabled]):checked[data-type="extra_fields"]').length > 0 ) { 331 $('.pms-paygate-extra-fields').hide() 332 $('.pms-paygate-extra-fields-' + $(paygate_selector + ':not([disabled]):checked[data-type="extra_fields"]').val() ).show() 333 } else if ( $(paygate_selector + ':not([disabled])[type="hidden"][data-type="extra_fields"]').length > 0 ) { 334 $('.pms-paygate-extra-fields').hide() 335 $('.pms-paygate-extra-fields-' + $(paygate_selector + ':not([disabled])[type="hidden"][data-type="extra_fields"]').val() ).show() 336 } 337 338 // Enable submit button 339 if ($pms_checked_subscription.length != 0) 340 $(pms_payment_buttons).attr('disabled', false).removeClass('pms-submit-disabled'); 341 342 } 343 344 } 345 346 // Hide credit card fields if it's a free plan 347 if ( $pms_checked_subscription.data('price') == 0 && !$.pms_plan_has_signup_fee() ) { 348 349 if ( $.pms_plan_is_prorated() ){ 350 351 if ( $.pms_checkout_is_recurring() ){ 352 353 if( typeof $pms_form != 'undefined' ) 354 $.pms_show_payment_fields( $pms_form ) 355 356 return 357 } 358 359 } 360 361 $('#pms-paygates-wrapper').hide() 362 $(paygate_selector).attr('disabled', true) 363 $(paygate_selector).closest('label').hide() 364 365 $('.pms-paygate-extra-fields').hide() 366 $('.pms-billing-details').hide() 367 $('.pms-section-billing-toggle').hide() 368 369 } 370 371 } 372 373 /** 374 * Handle the display of recurring period information for subscription plans 375 * e.g. pro-rate scenario with free time for a subscription that needs to recur 376 * 377 */ 378 function handle_plan_recurring_duration_display() { 379 380 if ( !( $( '#pms-change-subscription-form' ).length > 0 ) ) 381 return 382 383 $( 'input[name="subscription_plans"]' ).each( function( index, plan ){ 384 385 // don't do anything for plans that do not recur or if they don't have a prorated discount 386 if ( $(plan).data('recurring') == 3 || ( typeof $(plan).data('prorated_discount') == 'undefined' || $(plan).data('prorated_discount') == 0 ) ) 387 return 388
389 // show recurring data for plans that always recur 390 if ( ( $(plan).data('recurring') == 2 || settings_recurring == 2 || $('input[name="pms_recurring"]', $pms_auto_renew_field).prop('checked') ) && $( '.pms-subscription-plan-price__recurring', $(plan).parent() ) ) 391 $( '.pms-subscription-plan-price__recurring', $(plan).parent() ).show() 392 else 393 $( '.pms-subscription-plan-price__recurring', $(plan).parent() ).hide() 394 395 }) 396 397 } 398 399 /** 400 * Show billing fields if necessary 401 */ 402 function handle_billing_fields_display(){ 403 404 if( !( $pms_section_billing_details.length > 0 ) ) { 405 $('.pms-section-billing-toggle').hide() 406 return 407 } 408 409 if ( $pms_checked_subscription.length > 0 && !is_pb_email_confirmation_on && ( $pms_checked_subscription.data('price') != 0 || $.pms_plan_has_signup_fee( $pms_checked_subscription ) ) ) { 410 $('.pms-billing-details').attr('style', 'display: flex;'); 411 412 if ( $pms_checked_subscription.data('price') > 0 ) 413 $('.pms-section-billing-toggle').show() 414 else $('.pms-section-billing-toggle').hide() 415 } 416 417 let parentForm = $pms_section_billing_details.closest('form').attr('id'); 418 419 if ( parentForm === undefined || ( parentForm !== 'pms_edit-profile-form' && !$pms_checked_subscription.length ) ) { 420 $('.pms-section-billing-toggle').hide() 421 return 422 } 423 424 if ( $pms_billing_toggle.length > 0 ) { 425 426 if ( $pms_billing_toggle.is(':checked') ) { 427 $('.pms-billing-details').attr('style', 'display: flex;'); 428 } 429 else { 430 $('.pms-billing-details').hide(); 431 } 432 433 } 434 435 } 436 437 /** 438 * Show/Hide Cycles information in Subscription Plan price section on forms 439 */ 440 function handle_billing_cycles_display( selected_paygate ) { 441 let cyclesText = jQuery('.pms-subscription-plan-billing-cycles'); 442 443 let gateways = ['manual', 'stripe_connect', 'paypal_connect', 'authorize_net']; 444 445 if ( gateways.includes(selected_paygate) ) 446 cyclesText.show(); 447 else 448 cyclesText.hide(); 449 450 } 451 452 453 /** 454 * Disable the form submit button when the form is submitted 455 * 456 */ 457 jQuery(document).on( 'submit', '.pms-form', disable_form_submit_button ) 458 459 if( jQuery( '.wppb-register-user' ).length > 0 && jQuery( '.wppb-register-user .wppb-subscription-plans' ).length > 0 ) 460 jQuery(document).on('submit', '.wppb-register-user', disable_form_submit_button) 461 462 window.disable_form_submit_button = disable_form_submit_button; 463 function disable_form_submit_button( e ){ 464 465 if (jQuery(e.target).is('form')) { 466 var form = jQuery(e.target) 467 } else { 468 var form = jQuery(e) 469 } 470 471 var target_button = jQuery( 'input[type="submit"], button[type="submit"]', form ).not('#pms-apply-discount').not('input[name="pms_redirect_back"]')[0] 472 473 if ( $(target_button).hasClass('pms-submit-disabled') ) 474 return false 475 476 $(target_button).data('original-value', $(target_button).val()) 477 478 // Replace the button text with the placeholder 479 if (pms_payment_button_loading_placeholder_text.length > 0) { 480 481 $(target_button).addClass('pms-submit-disabled').val(pms_payment_button_loading_placeholder_text) 482 483 if ($(target_button).is('button')) 484 $(target_button).text(pms_payment_button_loading_placeholder_text) 485 486 } 487 488 } 489 490 491 /** 492 * Trigger a click on the checked subscription plan when checking / unchecking the 493 * auto-renew checkbox as this also takes into account whether the auto-renew field 494 * is checked, thus hiding the unneeded payment gateways 495 * 496 */ 497 $pms_auto_renew_field.click( function() { 498 499 handle_auto_renew_field_display() 500 handle_payment_gateways_display() 501 handle_plan_recurring_duration_display() 502 503 }); 504 505 /** 506 * Handle the Billing Fields Section toggle 507 */ 508 if ($pms_billing_toggle.length > 0) { 509 let allRequiredFilled = true; 510 511 $('.pms-billing-details .pms-field-required').each(function() { 512 let $input = $(this).find('input, select'); 513 514 if ($input.length > 0 && !$input.val()) { 515 allRequiredFilled = false;
516 return false; 517 } 518 }); 519 520 if ( !allRequiredFilled ) { 521 $pms_billing_toggle.prop('checked', true); 522 } 523 524 $pms_billing_toggle.on('change', function() { 525 handle_billing_fields_display(); 526 }); 527 528 } 529 530 531 /** 532 * Trigger a click on the selected subscription plan so that 533 * the rest of the checkout interface changes 534 * 535 */ 536 handle_auto_renew_field_display() 537 handle_payment_gateways_display() 538 handle_plan_recurring_duration_display() 539 handle_billing_fields_display() 540 541 /** 542 * Show the paygates inner wrapper 543 * 544 */ 545 $( '#pms-paygates-inner' ).css( 'visibility', 'visible' ); 546 547 548 /** 549 * Show/Hide Subscription Plan billing cycle information 550 * - info displayed with the Subscription Plan price on forms 551 */ 552 handle_billing_cycles_display( $pms_checked_paygate.val() ) 553 554 /** 555 * Compatibility when the form is placed inside an Elementor Popup 556 */ 557 jQuery(document).on('elementor/popup/show', function () { 558 559 if ($('.pms-form', $('.elementor-popup-modal')).length > 0) { 560 $pms_checked_subscription = jQuery( subscription_plan_selector + '[type=radio]' ).length > 0 ? jQuery( subscription_plan_selector + '[type=radio]:checked' ) : jQuery( subscription_plan_selector + '[type=hidden]' ) 561 562 handle_auto_renew_field_display() 563 handle_payment_gateways_display() 564 handle_plan_recurring_duration_display() 565 handle_billing_fields_display() 566 567 $('#pms-paygates-inner').css('visibility', 'visible'); 568 } 569 570 }) 571 572 /** 573 * WPPB Conditional Logic compatibility 574 */ 575 if ( $('.wppb-register-user').length != 0 && $('.wppb-subscription-plans').length != 0 ) { 576 577 // if there are 2 or more plans in the form, since they use the same meta name, only the LAST field from the 578 // PB Form Fields interface will have a default values selected, but we have no idea which field is displayed 579 // so we need to make sure the visible one has it's default plan selected 580 pmsHandleDefaultWPPBFormSelectedPlanOnLoad() 581 pmsHandleGatewaysDisplayRemove() 582 583 $(document).on( "wppbRemoveRequiredAttributeEvent", pmsHandleGatewaysDisplayRemove ) 584 $(document).on( "wppbAddRequiredAttributeEvent", pmsHandleGatewaysDisplayShow ) 585 $(document).on( "wppb_msf_next_step", pmsHandleGatewaysDisplayRemove ) 586 $(document).on( "wppb_msf_next_step", pmsHandleGatewaysDisplayShow ) 587 588 function pmsHandleGatewaysDisplayRemove( event = '' ) { 589 590 if( $( '#pms-paygates-wrapper' ).is( ':hidden' ) ) 591 return 592 593 if( event != '' ){ 594 595 if( event.type && event.type != 'wppb_msf_next_step' ){ 596 var element = event.target 597 598 if ( typeof $(element).attr('conditional-name') == 'undefined' || $(element).attr('conditional-name') != 'subscription_plans' ) 599 return 600 } 601 602 } 603 604 var visible_plans = false 605 606 $('.wppb-subscription-plans').each( function (index, item) { 607 608 var only_free_plans = true 609 610 var $checked = $('.pms-subscription-plan input[type=radio]:checked, .pms-subscription-plan input[type=hidden]', $(item)) 611 612 // Check if field is hidden via conditional logic 613 if ( $checked.attr('conditional-name') === 'subscription_plans' ) { 614 return false 615 } 616 617 if ( ( $checked.data('price') && $checked.data('price') > 0 ) || $.pms_plan_has_signup_fee( $checked ) ) { 618 only_free_plans = false 619 } 620 621 if ( only_free_plans ) 622 visible_plans = false 623 else 624 visible_plans = true 625 626 return false 627 628 }) 629 630 if( visible_plans === false ){ 631 632 $('#pms-paygates-wrapper').hide() 633 $( paygate_selector ).attr( 'disabled', true ) 634 $( paygate_selector ).closest( 'label' ).hide() 635 636 $('.pms-paygate-extra-fields').hide() 637 $('.pms-billing-details').hide() 638 $('.pms-section-billing-toggle').hide() 639 640 $('.pms-price-breakdown__holder').hide() 641 642 if(typeof element != 'undefined' && element.length > 0 ){ 643 $('input[type="submit"], button[type="submit"]', $(element).closest( '.pms-form, .wppb-register-user' ) ).show() 644 } 645 646 } else { 647 pmsHandleDefaultWPPBFormSelectedPlanOnLoad() 648 } 649 650 } 651 652 function pmsHandleGatewaysDisplayShow(event = '') { 653 654 if (event != '') { 655 if( event.type && event.type != 'wppb_msf_next_step' ){ 656 var element = event.target 657 658 if ( typeof $(element).attr('conditional-name') == 'undefined' || $(element).attr('conditional-name') != 'subscription_plans' ) 659 return 660 } 661 } 662 663 var visible_plans = false 664 665 $('.wppb-subscription-plans').each( function (index, item) { 666 667 var only_free_plans = true 668 669 var $checked = $('.pms-subscription-plan input[type=radio]:checked, .pms-subscription-plan input[type=hidden]', $(item) ) 670 671 // Check if field is hidden via conditional logic 672 if ( $checked.attr('conditional-name') === 'subscription_plans' ) { 673 return false 674 } 675 676 if ( $checked.data('price') && $checked.data('price' ) > 0) { 677 only_free_plans = false 678 } 679 680 if ( only_free_plans ) 681 visible_plans = false 682 else 683 visible_plans = true 684 685 return false 686 687 }) 688 689 if ( visible_plans === false ) { 690 691 $('#pms-paygates-wrapper').hide() 692 $(paygate_selector).attr('disabled', true) 693 $(paygate_selector).closest('label').hide() 694 695 $('.pms-paygate-extra-fields').hide() 696 $('.pms-billing-details').hide() 697 $('.pms-section-billing-toggle').hide() 698 699 $('.pms-price-breakdown__holder').hide() 700 701 if(typeof element != 'undefined' && element.length > 0 ){ 702 $('input[type="submit"], button[type="submit"]', $(element).closest( '.pms-form, .wppb-register-user' ) ).show() 703 } 704 705 } else { 706 707 $('#pms-paygates-wrapper').show() 708 $(paygate_selector).removeAttr('disabled') 709 $(paygate_selector).closest('label').show() 710 711 $('.pms-paygate-extra-fields').show() 712 $('.pms-billing-details').attr('style', 'display: flex;'); 713 $('.pms-section-billing-toggle').show() 714 715 $('.pms-price-breakdown__holder').show() 716 717 // If PayPal Connect is selected, show the PayPal Connect extra fields 718 if ( ( $( 'input[type=radio][name=pay_gate]:checked' ).val() == 'paypal_connect' || $('input[type=hidden][name=pay_gate]').val() == 'paypal_connect' ) && 719 ( !$( 'input[type=radio][name=pay_gate]:checked' ).is(':disabled') || !$('input[type=hidden][name=pay_gate]').is(':disabled') ) 720 ){ 721 $( '.pms-paygate-extra-fields-paypal_connect' ).show() 722 $( '.wppb-register-user .form-submit input[type="submit"], .wppb-register-user.form-submit button[type="submit"]' ).last().hide() 723 } 724 725 } 726 727 } 728 729 function pmsHandleDefaultWPPBFormSelectedPlanOnLoad() { 730 731 if( !( jQuery( '#wppb-register-user' ).length > 0 ) ) 732 return 733 734 // 2 or more plans in the form 735 if( !( jQuery( '.wppb-subscription-plans').length > 1 ) ) 736 return 737 738 jQuery('.wppb-subscription-plans' ).each( function(){ 739 740 if( jQuery( this ).is( ':visible' ) ){ 741 742 jQuery( this ).find("input[name=\'subscription_plans\']").each(function (index, item) { 743 744 if ( typeof jQuery(item).data("default-selected") != "undefined" && jQuery(item).data("default-selected") == true ) { 745 jQuery(item).prop("checked", "checked") 746 jQuery(item).trigger("click") 747 } 748 749 }) 750 751 return 752 } 753 754 }) 755 756 } 757 758 } 759 760 /** 761 * On the Change Subscription form change the button name based on which plans group the user clicks 762 */ 763 if( $('#pms-change-subscription-form').length > 0 ){ 764 765 if ( $pms_checked_subscription.closest('.pms-upgrade__group').hasClass('pms-upgrade__group--upgrade') ){ 766 767 $('#pms-change-subscription-form input[name="pms_change_subscription"]').val($('#pms-change-subscription-form input[name="pms_button_name_upgrade"]').val()) 768 $('#pms-change-subscription-form input[name="form_action"]').val($('#pms-change-subscription-form input[data-name="upgrade_subscription"]').val()) 769 770 } else if ( $pms_checked_subscription.closest('.pms-upgrade__group').hasClass('pms-upgrade__group--downgrade') ){ 771 772 $('#pms-change-subscription-form input[name="pms_change_subscription"]').val($('#pms-change-subscription-form input[name="pms_button_name_downgrade"]').val()) 773 $('#pms-change-subscription-form input[name="form_action"]').val($('#pms-change-subscription-form input[data-name="downgrade_subscription"]').val()) 774 775 } 776
777 $('#pms-change-subscription-form .pms-upgrade__group--upgrade .pms-subscription-plan input').on('click', function () { 778 779 $('#pms-change-subscription-form input[name="pms_change_subscription"]').val($('#pms-change-subscription-form input[name="pms_button_name_upgrade"]').val()) 780 $('#pms-change-subscription-form input[name="form_action"]').val($('#pms-change-subscription-form input[data-name="upgrade_subscription"]').val()) 781 782 }) 783 784 $('#pms-change-subscription-form .pms-upgrade__group--downgrade .pms-subscription-plan input').on('click', function () { 785 786 $('#pms-change-subscription-form input[name="pms_change_subscription"]').val($('#pms-change-subscription-form input[name="pms_button_name_downgrade"]').val()) 787 $('#pms-change-subscription-form input[name="form_action"]').val($('#pms-change-subscription-form input[data-name="downgrade_subscription"]').val()) 788 789 }) 790 791 $('#pms-change-subscription-form .pms-upgrade__group--change .pms-subscription-plan input').on('click', function () { 792 793 $('#pms-change-subscription-form input[name="pms_change_subscription"]').val($('#pms-change-subscription-form input[name="pms_button_name_change"]').val()) 794 $('#pms-change-subscription-form input[name="form_action"]').val('') 795 796 }) 797 798 } 799 800 }) 801 802 803 /* 804 * Add field error for a given element name 805 * 806 */ 807 $.pms_add_field_error = function( error, field_name ) { 808 809 if( error == '' || error == 'undefined' || field_name == '' || field_name == 'undefined' ) 810 return false; 811 812 $field = $('[name=' + field_name + ']'); 813 $field_wrapper = $field.closest('.pms-field'); 814 815 error = '<p>' + error + '</p>'; 816 817 if( $field_wrapper.find('.pms_field-errors-wrapper').length > 0 ) 818 $field_wrapper.find('.pms_field-errors-wrapper').html( error ); 819 else 820 $field_wrapper.append('<div class="pms_field-errors-wrapper pms-is-js">' + error + '</div>'); 821 822 } 823 824 $.pms_add_general_error = function( error ){ 825 if( error == '' || error == 'undefined' ) 826 return false 827 828 var target = $('.pms-form') 829 830 target.prepend( '<div class="pms_field-errors-wrapper pms-is-js"><p>' + error + '</p></div>' ) 831 } 832 833 $.pms_add_subscription_plans_error = function( error ){ 834 if( error == '' || error == 'undefined' ) 835 return false 836 837 $('<div class="pms_field-errors-wrapper pms-is-js"><p>' + error + '</p></div>').insertBefore( '#pms-paygates-wrapper' ) 838 } 839 840 $.pms_add_order_bumps_error = function( error ){ 841 if( error == '' || error == 'undefined' ) 842 return false 843 844 var $section = $('.pms-order-bumps').first() 845 846 if( $section.length ) { 847 $section.find( '.pms-order-bumps__error' ).remove() 848 $section.prepend( '<div class="pms_field-errors-wrapper pms-order-bumps__error pms-is-js"><p>' + error + '</p></div>' ) 849 return 850 } 851 852 // bumps section is not on the page (no configured bumps for the primary, or unsupported flow); fall back to the top-of-form general error 853 $.pms_add_general_error( error ) 854 } 855 856 $.pms_add_recaptcha_field_error = function( error, payment_button ){ 857 858 $field_wrapper = $( '#pms-recaptcha-register-wrapper', $(payment_button).closest('form') ) 859 860 error = '<p>' + error + '</p>' 861 862 if ( $field_wrapper.find('.pms_field-errors-wrapper').length > 0 ) 863 $field_wrapper.find('.pms_field-errors-wrapper').html(error) 864 else 865 $field_wrapper.append('<div class="pms_field-errors-wrapper pms-is-js">' + error + '</div>') 866 } 867 868 /** 869 * Check if a plan has trial enabled 870 */ 871 $.pms_plan_has_trial = function( element = null ) { 872 873 if( element == null ) 874 element = $pms_checked_subscription 875 876 if (typeof element.data('trial') == 'undefined' || element.data('trial') == '0' ) 877 return false 878 879 return true 880 881 } 882 883 /** 884 * Check if a plan has sign-up fee enabled 885 */ 886 $.pms_plan_has_signup_fee = function( element = null ) { 887 888 if( element == null ) 889 element = $pms_checked_subscription 890 891 if( typeof element.data('sign_up_fee') == 'undefined' || element.data('sign_up_fee') == '0' ) 892 return false 893 894 return true 895 896 } 897 898 /** 899 * Check if a plan is prorated 900 */ 901 $.pms_plan_is_prorated = function( element = null ) { 902 903 if ( !( $('#pms-change-subscription-form').length > 0 ) ) 904 return false 905 906 if( element == null ) 907 element = $pms_checked_subscription 908 909 if ( typeof element.data('prorated_discount') != 'undefined' && element.data('prorated_discount') > 0 ) 910 return true 911 912 return false 913 914 } 915 916 /** 917 * Checks if a given/selected plan plus the current form state create a recurring checkout 918 */ 919 $.pms_checkout_is_recurring = function( element = null ) { 920 921 if( element == null ) 922 element = $pms_checked_subscription 923 924 if ( ( settings_recurring == '2' || $('input[name="pms_recurring"]', $pms_auto_renew_field).prop('checked') || element.data('recurring') == 2 ) && element.data('recurring') != 3 ) 925 return true 926 927 return false 928 929 } 930 931 /** 932 * Function to hide payment fields 933 * 934 */ 935 $.pms_hide_payment_fields = function( form ) { 936 937 if( typeof form == 'undefined' ) 938 return 939 940 if ( typeof form.pms_paygates_wrapper == 'undefined' ) 941 form.pms_paygates_wrapper = form.find('#pms-paygates-wrapper').clone() 942 943 form.find('#pms-paygates-wrapper').replaceWith('<span id="pms-paygates-wrapper">') 944 945 form.find('.pms-paygate-extra-fields').hide() 946 947 // When hiding PayPal we need to restore the register button 948 if ( form.find('.pms-paygate-extra-fields-paypal_connect').length > 0 ){ 949 if ( typeof $pms_checked_paygate != 'undefined' && $pms_checked_paygate.val() == 'paypal_connect' ){
950 form.find( 'input[type="submit"], button[type="submit"]' ).show() 951 } 952 } 953 954 if ( typeof PMS_ChosenStrings !== 'undefined' && $.fn.chosen != undefined ) { 955 form.find('#pms_billing_country').chosen('destroy') 956 form.find('#pms_billing_state').chosen('destroy') 957 } 958 959 if ( typeof form.pms_billing_details == 'undefined' ) { 960 form.pms_billing_details = form.find('.pms-billing-details').clone() 961 } 962 963 form.find('.pms-billing-details').replaceWith('<span class="pms-billing-details">') 964 965 $('.pms-section-billing-toggle').hide(); 966 967 } 968 969 /** 970 * Function to show payment fields 971 * 972 */ 973 $.pms_show_payment_fields = function( form ) { 974 975 if( typeof form == 'undefined' ) 976 return 977 978 if ( typeof form.pms_paygates_wrapper != 'undefined' ) 979 form.find('#pms-paygates-wrapper').replaceWith( form.pms_paygates_wrapper ) 980 981 if ( typeof $pms_checked_paygate != 'undefined' && $pms_checked_paygate.data('type') == 'extra_fields' ) 982 form.find('.pms-paygate-extra-fields-' + $pms_checked_paygate.val() ).show() 983 984 // When showing PayPal we need to hide the register button 985 if ( form.find('.pms-paygate-extra-fields-paypal_connect').length > 0 ){ 986 if ( typeof $pms_checked_paygate != 'undefined' && $pms_checked_paygate.val() == 'paypal_connect' ){
987 form.find( 'input[type="submit"]:not([name="pms_redirect_back"]):not([id="pms-apply-discount"]), button[type="submit"]' ).hide() 988 } 989 } 990 991 if ( typeof form.pms_billing_details != 'undefined' ) { 992 993 form.find('.pms-billing-details').replaceWith(form.pms_billing_details) 994 995 $('.pms-section-billing-toggle').show(); 996 997 if ( typeof PMS_ChosenStrings !== 'undefined' && $.fn.chosen != undefined ) { 998 999 form.find('#pms_billing_country').chosen(PMS_ChosenStrings) 1000 1001 if ( $('#pms_billing_state option').length > 0 ) 1002 form.find('#pms_billing_state').chosen(PMS_ChosenStrings) 1003 1004 } 1005 1006 } 1007 1008 } 1009 1010 /** 1011 * Checks if a given/selected plan plus the current form state create a checkout without a payment, we call it setup_intents similar to Stripe 1012 * 1013 * - addons can override the decision by listening to the `pms_filter_checkout_is_setup_intents` jQuery event on document and returning a boolean (e.g. Order Bumps forces payment mode when bundle line items are selected) 1014 */ 1015 $.pms_checkout_is_setup_intents = function () { 1016 1017 let selected_plan = $(subscription_plan_selector + '[type=radio]').length > 0 ? $(subscription_plan_selector + '[type=radio]:checked') : $(subscription_plan_selector + '[type=hidden]') 1018 1019 let result = false 1020 1021 if ( typeof selected_plan.data('trial') != 'undefined' && selected_plan.data('trial') == '1' && !$.pms_plan_has_signup_fee( selected_plan ) ) 1022 result = true 1023 // If a 100% discount code is used, initial amount will be 0 1024 else if ( $('input[name="discount_code"]').length > 0 && $('input[name="discount_code"]').val().length > 0 && typeof selected_plan.data('price') != 'undefined' && selected_plan.data('price') == '0' ) 1025 result = true 1026 // Pro-rated subscriptions 1027 else if ($.pms_plan_is_prorated(selected_plan) && typeof selected_plan.data('price') != 'undefined' && selected_plan.data('price') == '0') 1028 result = true 1029 1030 let filtered = $(document).triggerHandler( 'pms_filter_checkout_is_setup_intents', [ result, selected_plan ] ) 1031 1032 return typeof filtered === 'boolean' ? filtered : result 1033 1034 } 1035 1036 /** 1037 * Adds validation errors to the WPPB form 1038 */ 1039 $.pms_form_add_wppb_validation_errors = function ( errors, current_button ) { 1040 1041 let scroll = false 1042 1043 // errors is of the form: FIELD_ID => FIELD_ERROR 1044 jQuery.each(errors, function (key, value) { 1045 1046 let field = jQuery('#wppb-form-element-' + key) 1047 1048 field.addClass('wppb-field-error') 1049 field.append(value) 1050 1051 scroll = true 1052 1053 }) 1054 1055 if ( scroll ) 1056 $.pms_form_scrollTo( '.wppb-register-user', current_button ) 1057 1058 } 1059 1060 /** 1061 * Adds validation errors to the Stripe credit card information 1062 */ 1063 $.pms_stripe_add_credit_card_error = function (error) { 1064 1065 if (error == '' || error == 'undefined') 1066 return false 1067 1068 $field_wrapper = $('.pms-paygate-extra-fields-stripe_connect'); 1069 1070 error = '<p>' + error + '</p>' 1071 1072 if ($field_wrapper.find('.pms_field-errors-wrapper').length > 0) 1073 $field_wrapper.find('.pms_field-errors-wrapper').html(error) 1074 else 1075 $field_wrapper.append('<div class="pms_field-errors-wrapper pms-is-js">' + error + '</div>') 1076 1077 } 1078 1079 $.pms_form_add_validation_errors = function (errors, payment_button) { 1080 1081 var scrollLocation = ''; 1082 1083 $.each(errors, function (index, value) { 1084 1085 if (value.target == 'form_general') { 1086 $.pms_add_general_error(value.message) 1087 1088 scrollLocation = '.pms-form' 1089 } else if (value.target == 'subscription_plan' || value.target == 'subscription_plans' || value.target == 'payment_gateway') { 1090 $.pms_add_subscription_plans_error(value.message) 1091 1092 if (scrollLocation == '') 1093 scrollLocation = '.pms-field-subscriptions' 1094 } else if (value.target == 'credit_card') { 1095 $.pms_stripe_add_credit_card_error(value.message) 1096 1097 if (scrollLocation == '') 1098 scrollLocation = '#pms-paygates-wrapper' 1099 } else if (value.target == 'order_bumps') { 1100 $.pms_add_order_bumps_error(value.message) 1101 1102 if (scrollLocation == '') 1103 scrollLocation = $('.pms-order-bumps').length ? '.pms-order-bumps' : '.pms-form' 1104 } else if (value.target == 'recaptcha-register') { 1105 1106 $.pms_add_recaptcha_field_error(value.message, payment_button) 1107 1108 } else { 1109 $.pms_add_field_error(value.message, value.target) 1110 1111 if ( scrollLocation == '' && value.target.indexOf('pms_billing') !== -1 ) 1112 scrollLocation = '.pms-billing-details' 1113 else if( scrollLocation == '' && value.target.indexOf('pms_gift_recipient_email') !== -1 ) 1114 scrollLocation = '.pms-gift-details' 1115 else 1116 scrollLocation = '.pms-form' 1117 } 1118 1119 }) 1120 1121 if ($(payment_button).attr('name') == 'pms_update_payment_method' && scrollLocation == '#pms-paygates-wrapper') 1122 scrollLocation = '#pms-stripe-connect'; 1123 1124 $.pms_form_scrollTo(scrollLocation, payment_button) 1125 1126 } 1127 1128 $.pms_form_reset_submit_button = function(target) { 1129 1130 if (!target.data || !target.data('original-value') || typeof target.data('original-value') == undefined) { 1131 value = target.val() 1132 } else { 1133 value = target.data('original-value') 1134 } 1135 1136 setTimeout(function () { 1137 target.attr('disabled', false).removeClass('pms-submit-disabled').val(value).blur() 1138 1139 if ($(target).is('button')) 1140 $(target).text(value) 1141 1142 }, 1) 1143 1144 } 1145 1146 $.pms_form_scrollTo = function( scrollLocation, payment_button ) { 1147 1148 var form = $( scrollLocation )[0] 1149 1150 if (typeof form == 'undefined') { 1151 $.pms_form_reset_submit_button( payment_button ) 1152 return 1153 } 1154 1155 var coord = form.getBoundingClientRect().top + window.scrollY 1156 var offset = -170 1157 1158 window.scrollTo({ 1159 top: coord + offset, 1160 behavior: 'smooth' 1161 }) 1162 1163 $.pms_form_reset_submit_button( payment_button ) 1164 1165 } 1166 1167 $.pms_form_remove_errors = function() { 1168 1169 $('.pms_field-errors-wrapper').remove() 1170 1171 if ($('.pms-stripe-error-message').length > 0) 1172 $('.pms-stripe-error-message').remove() 1173 1174 if ($('.wppb-register-user').length > 0) { 1175 1176 $('.wppb-form-error').remove() 1177 1178 $('.wppb-register-user .wppb-form-field').each(function () { 1179 1180 $(this).removeClass('wppb-field-error') 1181 1182 }) 1183 1184 } 1185 1186 } 1187 1188 $.pms_form_get_data = async function( current_button, verify_captcha = false ) { 1189 1190 if (!current_button) 1191 return false 1192 1193 var form = $(current_button).closest('form') 1194 1195 // promote duplicate item.name values to an array, keep single-value fields scalar 1196 // - serializeArray emits one entry per submitted value, so multi-value fields produce duplicate names 1197 // - downstream consumers expect single-value fields to stay scalar 1198 var data = form.serializeArray().reduce(function (obj, item) { 1199 1200 if ( typeof obj[item.name] !== 'undefined' ) { 1201 obj[item.name] = Array.isArray( obj[item.name] ) ? obj[item.name] : [obj[item.name]] 1202 obj[item.name].push( item.value ) 1203 } else { 1204 obj[item.name] = item.value 1205 } 1206 1207 return obj 1208 }, {}) 1209 1210 // setup our custom AJAX action and add the current page URL 1211 data.action = 'pms_process_checkout' 1212 data.current_page = window.location.href 1213 data.pms_nonce = $('#pms-process-checkout-nonce').val() 1214 data.form_type = $('.wppb-register-user .wppb-subscription-plans').length > 0 ? 'wppb' : $('.pms-ec-register-form').length > 0 ? 'pms_email_confirmation' : 'pms' 1215 1216 /** 1217 * Add the name of the submit button as a key to the request data 1218 * this is necessary for logged in actions like change, retry or renew subscription 1219 */ 1220 data[current_button.attr('name')] = true 1221 1222 /** 1223 * Add the form_action field from the form necessary for Change Subscription form requests 1224 */ 1225 if ($('input[name="form_action"]', form) && $('input[name="form_action"]', form).length > 0) 1226 data.form_action = $('input[name="form_action"]', form).val() 1227 1228 // add WPPB fields metadata to request if necessary 1229 if (data.form_type == 'wppb') { 1230 data.wppb_fields = $.pms_form_get_wppb_fields(current_button) 1231 1232 // Add the send credentials checkbox to the request separately 1233 if( $('input[name="send_credentials_via_email"]', form).length > 0 && $('input[name="send_credentials_via_email"]', form).is(':checked') ) 1234 data.send_credentials_via_email = 'sending' 1235 else 1236 data.send_credentials_via_email = '' 1237 1238 } 1239 1240 // if user is logged in, set form type to current form 1241 if ($('body').hasClass('logged-in')) 1242 data.form_type = $('input[type="submit"], button[type="submit"]', form).not('#pms-apply-discount').not('input[name="pms_redirect_back"]').attr('name') 1243 1244 // This will be used to determine if the checkout involves a payment or not in case of a trial subscription 1245 if ($.pms_checkout_is_setup_intents()) 1246 data.setup_intent = true 1247 1248 if (data.pms_current_subscription) 1249 data.subscription_id = data.pms_current_subscription 1250 1251 // Recaptcha Compatibility
1252 // If reCaptcha field was not validated, don't send data to the server 1253 if (verify_captcha && typeof data['g-recaptcha-response'] != 'undefined' && data['g-recaptcha-response'] == '') { 1254 1255 if ( data.form_type == 'wppb' ) 1256 $.pms_form_add_wppb_validation_errors({ recaptcha: { field: 'recaptcha', error: '<span class="wppb-form-error">This field is required</span>' } }, current_button) 1257 else 1258 $.pms_add_recaptcha_field_error( 'Please complete the reCaptcha.', current_button ) 1259 1260 $.pms_form_reset_submit_button( current_button ) 1261 1262 return false 1263 1264 } 1265 1266 return data 1267 1268 } 1269 1270 $.pms_form_get_wppb_fields = function( current_button ) { 1271 1272 var fields = {} 1273 1274 // Taken from Multi Step Forms 1275 jQuery('li.wppb-form-field', jQuery(current_button).closest('form')).each(function () { 1276 1277 if (jQuery(this).attr('class').indexOf('heading') == -1 && jQuery(this).attr('class').indexOf('wppb_billing') == -1 1278 && jQuery(this).attr('class').indexOf('wppb_shipping') == -1 && jQuery(this).attr('class').indexOf('wppb-shipping') == -1) { 1279 1280 var meta_name; 1281 1282 if (jQuery(this).hasClass('wppb-repeater') || jQuery(this).parent().attr('data-wppb-rpf-set') == 'template' || jQuery(this).hasClass('wppb-recaptcha')) { 1283 return true; 1284 } 1285 1286 if (jQuery(this).hasClass('wppb-send-credentials-checkbox')) 1287 return true; 1288 1289 /* exclude conditional required fields */ 1290 if (jQuery(this).find('[conditional-value]').length !== 0) { 1291 return true; 1292 } 1293 1294 fields[jQuery(this).attr('id')] = {}; 1295 fields[jQuery(this).attr('id')]['class'] = jQuery(this).attr('class'); 1296 1297 if (jQuery(this).hasClass('wppb-woocommerce-customer-billing-address')) { 1298 meta_name = 'woocommerce-customer-billing-address'; 1299 } else if (jQuery(this).hasClass('wppb-woocommerce-customer-shipping-address')) { 1300 meta_name = 'woocommerce-customer-shipping-address'; 1301 1302 if (!jQuery('.wppb-woocommerce-customer-billing-address #woo_different_shipping_address', jQuery(current_button).closest('form')).is(':checked')) { 1303 return true; 1304 } 1305 } else { 1306 meta_name = jQuery(this).find('label').attr('for'); 1307 1308 //fields[jQuery( this ).attr( 'id' )]['required'] = jQuery( this ).find( 'label' ).find( 'span' ).attr( 'class' ); 1309 fields[jQuery(this).attr('id')]['title'] = jQuery(this).find('label').first().text().trim(); 1310 } 1311 1312 fields[jQuery(this).attr('id')]['meta-name'] = meta_name; 1313 1314 if (jQuery(this).parent().parent().attr('data-wppb-rpf-meta-name')) { 1315 var repeater_group = jQuery(this).parent().parent(); 1316 1317 fields[jQuery(this).attr('id')]['extra_groups_count'] = jQuery(repeater_group).find('#' + jQuery(repeater_group).attr('data-wppb-rpf-meta-name') + '_extra_groups_count').val(); 1318 } 1319 1320 if (jQuery(this).hasClass('wppb-woocommerce-customer-billing-address')) { 1321 var woo_billing_fields_fields = {}; 1322 1323 jQuery('ul.wppb-woo-billing-fields li.wppb-form-field', jQuery(current_button).closest('form')).each(function () { 1324 if (!jQuery(this).hasClass('wppb_billing_heading')) { 1325 woo_billing_fields_fields[jQuery(this).find('label').attr('for')] = jQuery(this).find('label').text(); 1326 } 1327 }); 1328 1329 fields[jQuery(this).attr('id')]['fields'] = woo_billing_fields_fields; 1330 } 1331 1332 if (jQuery(this).hasClass('wppb-woocommerce-customer-shipping-address')) { 1333 var woo_shipping_fields_fields = {}; 1334 1335 jQuery('ul.wppb-woo-shipping-fields li.wppb-form-field', jQuery(current_button).closest('form')).each(function () { 1336 if (!jQuery(this).hasClass('wppb_shipping_heading')) { 1337 woo_shipping_fields_fields[jQuery(this).find('label').attr('for')] = jQuery(this).find('label').text(); 1338 } 1339 }); 1340 1341 fields[jQuery(this).attr('id')]['fields'] = woo_shipping_fields_fields; 1342 } 1343 } 1344 }) 1345 1346 return fields 1347 1348 } 1349 1350 /* 1351 * GDPR Delete button 1352 */ 1353 jQuery("#pms-delete-account").on("click", function (e) { 1354 e.preventDefault(); 1355 1356 if( typeof pmsGdpr === 'undefined' || typeof pmsGdpr.delete_url === 'undefined' ) 1357 return; 1358 1359 var pmsDeleteUser = prompt(pmsGdpr.delete_text); 1360 if( pmsDeleteUser === "DELETE" ) { 1361 window.location.replace(pmsGdpr.delete_url); 1362 } 1363 else{ 1364 alert( pmsGdpr.delete_error_text ); 1365 } 1366 }) 1367 1368}) 1369 1370 1371/* 1372 * Profile Builder Compatibility 1373 * 1374 */ 1375jQuery( function($) { 1376 1377 $(document).ready( function() { 1378 1379 /** 1380 * Hide email confirmation payment message if no subscription plan is checked, or a free subscription is selected 1381 */ 1382 1383 // Handle on document ready 1384 if ( ( $('.pms-subscription-plan input[type=radio][data-price="0"]').is(':checked') || $('.pms-subscription-plan input[type=hidden]').attr( 'data-
1384price' ) == '0' || 1385 $('.pms-subscription-plan input[type=radio]').prop('checked') == false ) && !$.pms_plan_has_signup_fee() ) { 1386 1387 $('.pms-email-confirmation-payment-message').hide() 1388 } 1389 1390 if( $('.pms-subscription-plan input[type=radio]').length > 0 ) { 1391 1392 var has_paid_subscription = false 1393 1394 $('.pms-subscription-plan input[type=radio]').each( function() { 1395 if( $(this).data('price') != 0 || $.pms_plan_has_signup_fee( $(this) ) ) 1396 has_paid_subscription = true 1397 }) 1398 1399 if( !has_paid_subscription ) 1400 $('.pms-email-confirmation-payment-message').hide() 1401 1402 } 1403 1404 // Handle clicking on the subscription plans 1405 $('.pms-subscription-plan input[type=radio]').click(function(){ 1406 1407 if ( $('.pms-subscription-plan input[type=radio][data-price="0"]').is(':checked') && !$.pms_plan_has_signup_fee( $(this) ) ) 1408 $('.pms-email-confirmation-payment-message').hide() 1409 else 1410 $('.pms-email-confirmation-payment-message').show() 1411 1412 }) 1413 1414 $('.wppb-edit-user input[required]').on('invalid', function(e){ 1415 $.pms_reset_submit_button( $('.wppb-edit-user .wppb-subscription-plans input[type="submit"]').first() ) 1416 }) 1417 1418 }) 1419 1420}) 1421 1422 1423/** 1424 * Billing Fields 1425 */ 1426jQuery( function($) { 1427 1428 $(document).ready( function() { 1429 1430 // States field 1431 if( typeof PMS_States == 'undefined' || !PMS_States ) 1432 return 1433 1434 pms_handle_billing_state_field_display() 1435 1436 $(document).on( 'change', '#pms_billing_country', function() { 1437 1438 pms_handle_billing_state_field_display() 1439 1440 }) 1441 1442 if( typeof PMS_ChosenStrings !== 'undefined' && $.fn.chosen != undefined ){ 1443 $('#pms_billing_country').chosen( PMS_ChosenStrings ) 1444 1445 if( $('#pms_billing_state option').length > 0 ) 1446 $('#pms_billing_state').chosen( PMS_ChosenStrings ) 1447 } 1448 1449 // Autocomplete email address 1450 $( 'input[name=pms_billing_email], input[name=pms_billing_first_name], input[name=pms_billing_last_name]' ).each(function () { 1451 1452 if ( $(this).val() != '' ) 1453 $(this).addClass('pms-has-value') 1454 1455 }) 1456 1457 }) 1458 1459 /** 1460 * Fill up Email Address, First Name and Last Name based on what the user has type in the other fields 1461 * 1462 */ 1463 $(document).on('keyup', '#pms_user_email, .wppb-form-field input[name=email]', function () { 1464 1465 if ( $(this).closest('form').find('[name=pms_billing_email]').length == 0 ) 1466 return false 1467 1468 if ( $(this).closest('form').find('[name=pms_billing_email]').hasClass('pms-has-value') ) 1469 return false 1470 1471 $(this).closest('form').find('[name=pms_billing_email]').val( $(this).val() ) 1472 1473 }) 1474 1475 $(document).on('keyup', '#pms_first_name', function () { 1476 1477 if ( $(this).closest('form').find('[name=pms_billing_first_name]').length == 0 ) 1478 return false 1479 1480 if ( $(this).closest('form').find('[name=pms_billing_first_name]').hasClass('pms-has-value') ) 1481 return false 1482 1483 $(this).closest('form').find('[name=pms_billing_first_name]').val( $(this).val() ) 1484 1485 }) 1486 1487 $(document).on('keyup', '#pms_last_name', function () { 1488 1489 if ( $(this).closest('form').find('[name=pms_billing_last_name]').length == 0 ) 1490 return false 1491 1492 if ( $(this).closest('form').find('[name=pms_billing_last_name]').hasClass('pms-has-value') ) 1493 return false 1494 1495 $(this).closest('form').find('[name=pms_billing_last_name]').val( $(this).val() ) 1496 1497 }) 1498 1499 function pms_handle_billing_state_field_display(){ 1500 1501 var country = $('#pms_billing_country').val() 1502 1503 if( PMS_States[country] ){ 1504 1505 if( typeof PMS_ChosenStrings !== 'undefined' && $.fn.chosen != undefined ) 1506 $('.pms-billing-state__select').chosen('destroy') 1507 1508 $('.pms-billing-state__select option').remove() 1509 $('.pms-billing-state__select').append('<option value=""></option>'); 1510 1511 for( var key in PMS_States[country] ){ 1512 if( PMS_States[country].hasOwnProperty(key) ) 1513 $('.pms-billing-state__select').append('<option value="'+ key +'">'+ PMS_States[country][key] +'</option>') 1514 } 1515 1516 var prevValue = $('.pms-billing-state__input').val() 1517 1518 if( prevValue != '' ) 1519 $('.pms-billing-state__select').val( prevValue ) 1520 1521 $('.pms-billing-state__input').removeAttr('name').removeAttr('id').hide() 1522 $('.pms-billing-state__select').attr('name','pms_billing_state').attr('id','pms_billing_state').show() 1523 1524 if( typeof PMS_ChosenStrings !== 'undefined' && $.fn.chosen != undefined ) 1525 $('.pms-billing-state__select').chosen( PMS_ChosenStrings ) 1526 1527 } else { 1528 1529 if( typeof PMS_ChosenStrings !== 'undefined' && $.fn.chosen != undefined ) 1530 $('.pms-billing-state__select').chosen('destroy') 1531 1532 $('.pms-billing-state__select').removeAttr('name').removeAttr('id').hide() 1533 $('.pms-billing-state__input').attr('name','pms_billing_state').attr('id','pms_billing_state').show() 1534 1535 } 1536 1537 } 1538 1539 /** 1540 * Extra Subscription and Discount Options add-on -> Show/Hide Invite code input 1541 * 1542 */ 1543 var $inviteCodeField = $(".pms-invite-code-field"); 1544
1545 if( $inviteCodeField.length > 0 ){ 1546 toggleInviteCodeField(); 1547 1548 $(document).on("change", "input[name='subscription_plans']", toggleInviteCodeField); 1549 } 1550 1551 function toggleInviteCodeField() { 1552 var $subscriptionPlans = $("input[name='subscription_plans']"); 1553 1554 if( $subscriptionPlans.length == 0 ) { 1555 $inviteCodeField.hide(); 1556 return; 1557 } 1558 1559 var $selected; 1560 1561 if($subscriptionPlans.length === 1){ 1562 $selected = $subscriptionPlans; 1563 } 1564 else if($subscriptionPlans.length > 1){ 1565 $selected = $("input[name='subscription_plans']:checked"); 1566 } 1567 1568 if (!$selected || !$selected.length) { 1569 $inviteCodeField.hide(); 1570 return; 1571 } 1572 1573 var hasInviteCode = ($selected.attr("data-has_invite_code") || "").toLowerCase(); 1574 1575 $inviteCodeField.toggle(hasInviteCode === "yes"); 1576 } 1577}) 1578 1579
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.