| @@ -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(); |