PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.86
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.86
51.1.86 51.1.84 51.1.85 51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 All 40 releases
← All changes | includes/widgets/Pricing_Calculator/script.js +36 -36 51.1.63 → 51.1.86 View file →
@@ -36,9 +36,9 @@
36 36 var $summaryItems = $calculator.find('.king-pricing-calculator__summary-items');
37 37 var $calculateButton = $calculator.find('.king-pricing-calculator__calculate-button');
38 38
39 39 // Debug info - log initial calculator settings
40 - console.log('Calculator initialized with base price:', basePrice);
40 + // console.log('Calculator initialized with base price:', basePrice);
41 41
42 42 // Get ajaxurl from localized script if it exists, fallback to global
43 43 var ajaxUrl = (typeof king_addons_calculator_vars !== 'undefined') ? king_addons_calculator_vars.ajaxurl : (typeof ajaxurl !== 'undefined' ? ajaxurl : '');
44 44 // Get nonces from localized script
@@ -123,15 +123,15 @@
123 123 var $field = $(this);
124 124 var fieldType = $field.data('field-type');
125 125
126 126 // Debug info - log field attributes
127 - console.log('Field:', fieldType, 'Price Type:', $field.data('price-type'), 'Price:', $field.data('price'));
127 + // console.log('Field:', fieldType, 'Price Type:', $field.data('price-type'), 'Price:', $field.data('price'));
128 128
129 129 // Check if custom formula is used (Pro feature)
130 130 if ($field.data('price-type') === 'custom') {
131 131 // Show a one-time console message
132 132 if (!window.customFormulaMessageShown) {
133 - console.info('Custom formula calculation requires Pro version.');
133 + // console.info('Custom formula calculation requires Pro version.');
134 134 window.customFormulaMessageShown = true;
135 135 }
136 136 }
137 137
@@ -248,9 +248,9 @@
248 248 var total = basePrice;
249 249 var summaryHtml = '';
250 250
251 251 // Debug info
252 - console.log('Starting calculation with base price:', total);
252 + // console.log('Starting calculation with base price:', total);
253 253
254 254 // Advanced Formula will be applied after default calculation
255 255
256 256 // Process all fields in DOM order (sequential calculation)
@@ -330,9 +330,9 @@
330 330 '<span class="king-pricing-calculator__summary-value">+' + sanitizeHtml(formatPrice(subTotal)) + '</span>' +
331 331 '</div>';
332 332 }
333 333
334 - console.log('Field (add):', fieldLabel, 'Value:', fieldValue, 'Price:', fieldPrice, 'Subtotal:', subTotal, 'Total:', total);
334 + // console.log('Field (add):', fieldLabel, 'Value:', fieldValue, 'Price:', fieldPrice, 'Subtotal:', subTotal, 'Total:', total);
335 335
336 336 } else if (priceType === 'multiply') {
337 337 // For number/range: multiply total by the field value
338 338 if (fieldType === 'number' || fieldType === 'range') {
@@ -357,9 +357,9 @@
357 357 '</div>';
358 358 }
359 359 }
360 360
361 - console.log('Field (multiply):', fieldLabel, 'Value:', fieldValue, 'BeforeOp:', beforeOp, 'Total:', total);
361 + // console.log('Field (multiply):', fieldLabel, 'Value:', fieldValue, 'BeforeOp:', beforeOp, 'Total:', total);
362 362
363 363 } else if (priceType === 'custom') {
364 364 // In the free version, treat custom formula as add (fallback)
365 365 if (fieldType === 'number' || fieldType === 'range') {
@@ -387,13 +387,13 @@
387 387 '<span class="king-pricing-calculator__summary-value">' + sanitizeHtml(formatPrice(subTotal)) + '</span>' +
388 388 '</div>';
389 389 }
390 390
391 - console.log('Field (custom/fallback):', fieldLabel, 'Added:', subTotal, 'Total:', total);
391 + // console.log('Field (custom/fallback):', fieldLabel, 'Added:', subTotal, 'Total:', total);
392 392 }
393 393
394 394 } catch (fieldError) {
395 - console.error('Error processing field:', fieldLabel, fieldError);
395 + // console.error('Error processing field:', fieldLabel, fieldError);
396 396 }
397 397 });
398 398
399 399 // Advanced Formula override (Pro) after default calculation loops
@@ -425,10 +425,10 @@
425 425 }
426 426 });
427 427
428 428 // For debugging custom formulas
429 - console.log('Available field IDs:', fieldsMap);
430 - console.log('User-friendly field aliases:', aliasMap);
429 + // console.log('Available field IDs:', fieldsMap);
430 + // console.log('User-friendly field aliases:', aliasMap);
431 431
432 432 // Apply chosen formula on the aggregated total
433 433 var newTotal = total;
434 434 if (formulaType === 'exponential') {
@@ -442,9 +442,9 @@
442 442 var customCode = $calculator.data('customFormula') || '';
443 443 try {
444 444 // Security fix: Only allow safe mathematical operations
445 445 if (!isCustomFormulaSafe(customCode)) {
446 - console.error('Custom formula contains unsafe code');
446 + // console.error('Custom formula contains unsafe code');
447 447 return;
448 448 }
449 449 // Pass both the full field map and user-friendly aliases
450 450 var fn = new Function('fields', 'basePrice', 'aliases', customCode);
@@ -449,9 +449,9 @@
449 449 // Pass both the full field map and user-friendly aliases
450 450 var fn = new Function('fields', 'basePrice', 'aliases', customCode);
451 451 newTotal = fn(fieldsMap, basePrice, aliasMap);
452 452 } catch (e) {
453 - console.error('Custom formula error:', e);
453 + // console.error('Custom formula error:', e);
454 454 }
455 455
456 456 function isCustomFormulaSafe(formula) {
457 457 // Only allow safe mathematical operations
@@ -487,14 +487,14 @@
487 487 }
488 488
489 489 // Final check to prevent NaN
490 490 if (isNaN(total)) {
491 - console.error('Total calculation resulted in NaN');
491 + // console.error('Total calculation resulted in NaN');
492 492 total = basePrice;
493 493 }
494 494
495 495 // Debug info
496 - console.log('Final total:', total);
496 + // console.log('Final total:', total);
497 497
498 498 // Update the total price
499 499 $totalPrice.text(formatPrice(total));
500 500
@@ -500,9 +500,9 @@
500 500
501 501 // Update the summary items
502 502 $summaryItems.html(summaryHtml);
503 503 } catch(e) {
504 - console.error('Calculation error:', e);
504 + // console.error('Calculation error:', e);
505 505 $totalPrice.text(formatPrice(basePrice));
506 506 }
507 507 }
508 508
@@ -510,9 +510,9 @@
510 510 * Format a price number with proper separators
511 511 */
512 512 function formatPrice(number) {
513 513 if (isNaN(number)) {
514 - console.error('Attempting to format NaN as price');
514 + // console.error('Attempting to format NaN as price');
515 515 number = 0;
516 516 }
517 517 var parts = number.toFixed(decimalPlaces).toString().split('.');
518 518 parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, thousandSeparator);
@@ -556,15 +556,15 @@
556 556 conditionalRules = $calculator.data('conditionalRules');
557 557
558 558 // If that doesn't work, try to get the raw attribute and parse it
559 559 if (!conditionalRules && $calculator.attr('data-conditional-rules')) {
560 - console.log('Found data-conditional-rules attribute, trying to parse:', $calculator.attr('data-conditional-rules'));
560 + // console.log('Found data-conditional-rules attribute, trying to parse:', $calculator.attr('data-conditional-rules'));
561 561 conditionalRules = JSON.parse($calculator.attr('data-conditional-rules'));
562 562 }
563 563
564 - console.log('Conditional rules loaded:', conditionalRules);
564 + // console.log('Conditional rules loaded:', conditionalRules);
565 565 } catch (e) {
566 - console.error('Error parsing conditional rules:', e);
566 + // console.error('Error parsing conditional rules:', e);
567 567 }
568 568
569 569 // Add to Cart Integration
570 570 $calculator.find('.king-pricing-calculator-pro__add-to-cart-button').on('click', function() {
@@ -746,9 +746,9 @@
746 746 // Save to localStorage
747 747 localStorage.setItem(storageKey, JSON.stringify(fieldsData));
748 748 alert('Calculation saved successfully.');
749 749 } catch (error) {
750 - console.error('Error saving calculation:', error);
750 + // console.error('Error saving calculation:', error);
751 751 alert('There was an error saving your calculation. Please try again.');
752 752 }
753 753 });
754 754
@@ -806,9 +806,9 @@
806 806 } else {
807 807 alert('Calculation loaded successfully.');
808 808 }
809 809 } catch (error) {
810 - console.error('Error loading calculation:', error);
810 + // console.error('Error loading calculation:', error);
811 811 alert('There was an error loading your calculation. The saved data may be corrupted.');
812 812 }
813 813 });
814 814
@@ -813,9 +813,9 @@
813 813 });
814 814
815 815 // Conditional Logic
816 816 if (conditionalRules) {
817 - console.log('Conditional rules found:', conditionalRules);
817 + // console.log('Conditional rules found:', conditionalRules);
818 818 function evaluateCondition(val, operator, expected) {
819 819 try {
820 820 // Convert values for proper comparison
821 821 var compVal = val;
@@ -827,9 +827,9 @@
827 827 compExpected = parseFloat(expected);
828 828
829 829 // Check if we have valid numbers
830 830 if (isNaN(compVal) || isNaN(compExpected)) {
831 - console.warn('Invalid numeric comparison with NaN:', val, operator, expected);
831 + // console.warn('Invalid numeric comparison with NaN:', val, operator, expected);
832 832 return false;
833 833 }
834 834 }
835 835
@@ -839,9 +839,9 @@
839 839 return operator === 'is_checked' ? compVal === true : compVal === false;
840 840 }
841 841
842 842 // Log the comparison
843 - console.log('Comparing:', compVal, operator, compExpected);
843 + // console.log('Comparing:', compVal, operator, compExpected);
844 844
845 845 // Perform the comparison
846 846 switch (operator) {
847 847 case 'equal': return compVal == compExpected;
@@ -851,14 +851,14 @@
851 851 case 'contains': return ('' + compVal).indexOf(compExpected) !== -1;
852 852 default: return false;
853 853 }
854 854 } catch (e) {
855 - console.error('Error evaluating condition:', e);
855 + // console.error('Error evaluating condition:', e);
856 856 return false;
857 857 }
858 858 }
859 859 $.each(conditionalRules, function(_, rule) {
860 - console.log('Processing rule:', rule);
860 + // console.log('Processing rule:', rule);
861 861
862 862 // Improve field selection to handle both custom IDs and auto-generated IDs
863 863 var $ifField, $targetField;
864 864
@@ -875,21 +875,21 @@
875 875 // Try finding a field with a custom ID (king-calc-*)
876 876 $targetField = $calculator.find('[data-field-id="king-calc-' + rule.target_field + '"]');
877 877 }
878 878
879 - console.log('Condition field found:', $ifField.length > 0, 'Target field found:', $targetField.length > 0);
879 + // console.log('Condition field found:', $ifField.length > 0, 'Target field found:', $targetField.length > 0);
880 880
881 881 // Log actual field IDs to help debug
882 882 if ($ifField.length > 0) {
883 - console.log('If field ID:', $ifField.data('field-id'));
883 + // console.log('If field ID:', $ifField.data('field-id'));
884 884 }
885 885 if ($targetField.length > 0) {
886 - console.log('Target field ID:', $targetField.data('field-id'));
886 + // console.log('Target field ID:', $targetField.data('field-id'));
887 887 }
888 888
889 889 // If either field is not found, skip this rule
890 890 if (!$ifField.length || !$targetField.length) {
891 - console.warn('Could not find one or both fields for this rule, skipping');
891 + // console.warn('Could not find one or both fields for this rule, skipping');
892 892 return true; // Continue to next rule
893 893 }
894 894
895 895 function applyRule() {
@@ -896,9 +896,9 @@
896 896 var val;
897 897 var type = $ifField.data('field-type');
898 898
899 899 // Log the field type to debug
900 - console.log('Evaluating field type:', type);
900 + // console.log('Evaluating field type:', type);
901 901
902 902 if (type === 'checkbox' || type === 'switch') {
903 903 val = $ifField.find('input[type="checkbox"]').prop('checked');
904 904 } else if (type === 'radio') {
@@ -907,12 +907,12 @@
907 907 val = $ifField.find('input, select').val();
908 908 }
909 909
910 910 // Log the actual field value
911 - console.log('Field value:', val, 'comparing with:', rule.value, 'using operator:', rule.operator);
911 + // console.log('Field value:', val, 'comparing with:', rule.value, 'using operator:', rule.operator);
912 912
913 913 var result = evaluateCondition(val, rule.operator, rule.value);
914 - console.log('Condition evaluation result:', result);
914 + // console.log('Condition evaluation result:', result);
915 915
916 916 // Apply the action based on the result
917 917 try {
918 918 switch (rule.action) {
@@ -951,18 +951,18 @@
951 951 case 'set_value':
952 952 if (result) {
953 953 var $input = $targetField.find('input, select');
954 954 $input.val(rule.set_value).trigger('change');
955 - console.log('Set value to:', rule.set_value);
955 + // console.log('Set value to:', rule.set_value);
956 956 }
957 957 break;
958 958 }
959 959 } catch (e) {
960 - console.error('Error applying action:', e);
960 + // console.error('Error applying action:', e);
961 961 }
962 962
963 963 // Log the action taken
964 - console.log('Applied action:', rule.action, 'with result:', result);
964 + // console.log('Applied action:', rule.action, 'with result:', result);
965 965 }
966 966 $ifField.on('change input', applyRule);
967 967
968 968 // Also execute immediately once to set initial state