| @@ -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,13 +84,14 @@ | ||
| 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") { | |
| 93 | + if (!selectedAction || selectedAction === "-1") { | |
| 88 | 94 | alert("Please select a bulk action."); |
| 89 | 95 | return false; |
| 90 | 96 | } |
| 91 | 97 | |
| @@ -94,24 +100,9 @@ | ||
| 94 | 100 | alert("Please select at least one 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 |