| @@ -12,10 +12,15 @@ | ||
| 12 | 12 | } else { |
| 13 | 13 | jQuery(".show_if_subscription").hide(); |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | + // WooCommerce fires this from its variations AJAX callback, before it removes | |
| 17 | + // the panel's loading overlay. A product with no variations yet renders no | |
| 18 | + // `.woocommerce_variations[data-total]`, and JSON.parse(undefined) threw out | |
| 19 | + // of that callback, leaving the Variations panel spinning forever. No count | |
| 20 | + // means no variations. | |
| 16 | 21 | jQuery(document).on("woocommerce_variations_loaded", () => { |
| 17 | - let total_variations = JSON.parse(jQuery(".woocommerce_variations").attr("data-total")); | |
| 22 | + let total_variations = parseInt(jQuery(".woocommerce_variations").attr("data-total"), 10) || 0; | |
| 18 | 23 | for (let index = 0; index < total_variations; index++) { |
| 19 | 24 | let element = document.getElementById("subscrpt_enable[" + index + "]"); |
| 20 | 25 | if (element && element.checked) { |
| 21 | 26 | jQuery(".show_if_subscription_" + index).show(); |
| @@ -79,39 +84,25 @@ | ||
| 79 | 84 | |
| 80 | 85 | // Prevent default form submission for bulk actions |
| 81 | 86 | e.preventDefault(); |
| 82 | 87 | |
| 83 | - var action = jQuery('select[name="action"]').val(); | |
| 84 | - var action2 = jQuery('select[name="action2"]').val(); | |
| 85 | - var selectedAction = action !== "-1" ? action : action2; | |
| 88 | + // Support both native <select> and hidden <input> (adv-select component) | |
| 89 | + var action = jQuery('[name="action"]').val(); | |
| 90 | + var action2 = jQuery('[name="action2"]').val(); | |
| 91 | + var selectedAction = action && action !== "-1" ? action : action2; | |
| 86 | 92 | |
| 87 | - if (selectedAction === "-1") { | |
| 88 | - alert("Please select a bulk action."); | |
| 93 | + if (!selectedAction || selectedAction === "-1") { | |
| 94 | + alert(wp.i18n.__("Please select a bulk action.", "subscription")); | |
| 89 | 95 | return false; |
| 90 | 96 | } |
| 91 | 97 | |
| 92 | 98 | var checkedBoxes = jQuery('input[name="subscription_ids[]"]:checked'); |
| 93 | 99 | if (checkedBoxes.length === 0) { |
| 94 | - alert("Please select at least one subscription."); | |
| 100 | + alert(wp.i18n.__("Please select at least one subscription.", "subscription")); | |
| 95 | 101 | return false; |
| 96 | 102 | } |
| 97 | 103 | |
| 98 | - // Confirm destructive actions | |
| 99 | - if (selectedAction === "delete") { | |
| 100 | - if ( | |
| 101 | - !confirm( | |
| 102 | - "Are you sure you want to permanently delete the selected subscriptions? This action cannot be undone.", | |
| 103 | - ) | |
| 104 | - ) { | |
| 105 | - return false; | |
| 106 | - } | |
| 107 | - } else if (selectedAction === "trash") { | |
| 108 | - if (!confirm("Are you sure you want to move the selected subscriptions to trash?")) { | |
| 109 | - return false; | |
| 110 | - } | |
| 111 | - } | |
| 112 | - | |
| 113 | - // Handle bulk action via AJAX | |
| 104 | + // Handle bulk action via AJAX (confirm already handled by adv-select data-confirm) | |
| 114 | 105 | handleBulkAction(selectedAction, checkedBoxes); |
| 115 | 106 | }); |
| 116 | 107 | |
| 117 | 108 | // AJAX function to handle bulk actions |
| @@ -123,9 +114,9 @@ | ||
| 123 | 114 | |
| 124 | 115 | // Show loading state |
| 125 | 116 | var submitButton = jQuery('input[name="bulk_action"]:focus, input[name="bulk_action2"]:focus'); |
| 126 | 117 | var originalText = submitButton.val(); |
| 127 | - submitButton.val("Processing...").prop("disabled", true); | |
| 118 | + submitButton.val(wp.i18n.__("Processing…", "subscription")).prop("disabled", true); | |
| 128 | 119 | |
| 129 | 120 | // Make AJAX request |
| 130 | 121 | jQuery.ajax({ |
| 131 | 122 | url: wp_subscription_ajax.ajaxurl, |
| @@ -145,13 +136,16 @@ | ||
| 145 | 136 | window.location.reload(); |
| 146 | 137 | }, 1000); |
| 147 | 138 | } else { |
| 148 | 139 | // Show error message |
| 149 | - showAdminNotice(response.data.message || "An error occurred while processing the bulk action.", "error"); | |
| 140 | + showAdminNotice( | |
| 141 | + response.data.message || wp.i18n.__("An error occurred while processing the bulk action.", "subscription"), | |
| 142 | + "error", | |
| 143 | + ); | |
| 150 | 144 | } |
| 151 | 145 | }, |
| 152 | 146 | error: function () { |
| 153 | - showAdminNotice("An error occurred while processing the bulk action.", "error"); | |
| 147 | + showAdminNotice(wp.i18n.__("An error occurred while processing the bulk action.", "subscription"), "error"); | |
| 154 | 148 | }, |
| 155 | 149 | complete: function () { |
| 156 | 150 | // Reset button state |
| 157 | 151 | submitButton.val(originalText).prop("disabled", false); |
| @@ -193,9 +187,12 @@ | ||
| 193 | 187 | "simple" !== subscrpt_product_type.val() && |
| 194 | 188 | "variable" !== subscrpt_product_type.val() |
| 195 | 189 | ) { |
| 196 | 190 | const confirmTypeChange = confirm( |
| 197 | - "Are you sure to change the product type ? If product type changed then You'll lose related subscriptions beacuse of they can't be renewed !", | |
| 191 | + wp.i18n.__( | |
| 192 | + "Are you sure you want to change the product type? Its subscriptions can no longer be renewed.", | |
| 193 | + "subscription", | |
| 194 | + ), | |
| 198 | 195 | ); |
| 199 | 196 | if (confirmTypeChange) { |
| 200 | 197 | latest_value_of_subscrpt_product_type = subscrpt_product_type.val(); |
| 201 | 198 | } else { |