1/** 2 * Additional fields 3 * 4 * @description: Display or hide additional fields from WooCommerce Subscription edit product 5 * 6 */ 7 8 9jQuery(document).ready(function ($) { 10 11 /*if ( 2 > $('[id^="_ccp_minimum_period"]').val() ) { 12 13 $('[id^="_ccp_minimum_period"]').parent().siblings('[class^="_ccp_cooling_off_period"]').css({"display": "none"}); 14 $('[id^="_ccp_minimum_period"]').parent().siblings('[class^="_ccp_rolling_cycle"]').css({"display": "none"}); 15 $('[id^="_ccp_minimum_period"]').parent().siblings('[class^="_ccp_disbale_end_cancellation"]').css({"display": "none"}); 16 $('[id^="_ccp_minimum_period"]').parent().siblings('[class^="_ccp_cancel_message"]').css({"display": "none"}); 17 $('[id^="_ccp_minimum_period"]').parent().siblings('[class^="_ccp_suspend_button"]').css({"display": "none"}); 18 $('[id^="_ccp_minimum_period"]').parent().siblings('[class^="_ccp_switch_button"]').css({"display": "none"}); 19 }*/ 20 21 $('body').on('change', '[id^="_ccp_cancellation_window_action"]', function () { 22 if ('' == $(this).val() ) { 23 $(this).siblings('.ccp_cancellation_window_action_options').css({"display": "none"}); 24 $(this).siblings('.ccp_cancellation_window_action_anytime').css({"display": "flex"}); 25 } else { 26 $(this).siblings('.ccp_cancellation_window_action_options').css({"display": "flex"}); 27 $(this).siblings('.ccp_cancellation_window_action_anytime').css({"display": "none"}); 28 } 29 30 } ); 31 $('body').on('change', '[id^="_ccp_minimum_period"]', function () { 32 if (1 < $(this).val() ) { 33 $(this).parent().siblings('.ccp_minimum_period_options').css({"display": "block"}); 34 } else { 35 $(this).parent().siblings('.ccp_minimum_period_options').css({"display": "none"}); 36 } 37 38 } ); 39 $('body').on('change', '[id^="_ccp_rolling_cycle"]', function () { 40 if (('' != $(this).val()) && (1 < $(this).val())) { 41 $(this).parent().siblings('.ccp_display_disable_end_cancellation').css({"display": "block"}); 42 } else { 43 $(this).parent().siblings('.ccp_display_disable_end_cancellation').css({"display": "none"}); 44 } 45 46 } ); 47 48 $('input[name="_cancellation_rule_button_behaviour"]').on('change', function() { 49 var cancellation_rule_button_selected = $('input[name="_cancellation_rule_button_behaviour"]:checked').val(); 50 $('.scn_notice').hide(); 51 $('.ccp_cancellation_window_box').hide(); 52 if (cancellation_rule_button_selected === '') { 53 $('.scn_notice').hide(); 54 $('.ccp_cancellation_window_box').hide(); 55 } 56 else if (cancellation_rule_button_selected === 'cancellation-rules') { 57 $('.scn_notice').show(); 58 $('.ccp_cancellation_window_box').show(); 59 } 60 61 }).trigger('change'); 62 63 //Variable Products Support 64 $(document).on('change', 'input[name^="_cancellation_rule_button_behaviour["]', function() { 65 var $variationBox = $(this).closest('.woocommerce_variation'); 66 var selected = $variationBox.find('input[name^="_cancellation_rule_button_behaviour["]:checked').val(); 67 68 // console.log("Variation box id:", $variationBox.find('.variable_post_id').val()); 69 70 $variationBox.find('.scn_notice').hide(); 71 $variationBox.find('.ccp_cancellation_window_box').hide(); 72 73 if (selected == 'cancellation-rules') { 74 $variationBox.find('.scn_notice').show(); 75 $variationBox.find('.ccp_cancellation_window_box').show(); 76 } 77 }); 78 79 // â Run once on load for each variation 80 $('input[name^="_cancellation_rule_button_behaviour["]:checked').trigger('change'); 81 82 //WCSATT Products 83 $(document).on('change', '.subscription_scheme input[name^="wcsatt_schemes"][name$="[scn_button_behaviour]"]', function() { 84 var $schemeBox = $(this).closest('.subscription_scheme'); 85 var selectedItem = $schemeBox.find('input[name^="wcsatt_schemes"][name$="[scn_button_behaviour]"]:checked').val(); 86 87 $schemeBox.find('.scn_notice').hide(); 88 $schemeBox.find('.ccp_cancellation_window_box').hide(); 89 90 if (selectedItem == 'cancellation-rules') { 91 $schemeBox.find('.scn_notice').show(); 92 $schemeBox.find('.ccp_cancellation_window_box').show(); 93 } 94 }); 95 96 // â Run once on load for each .subscription_scheme 97 $('input[name^="_cancellation_rule_button_behaviour["]:checked').trigger('change'); 98 99 // $('.subscription_schemes .subscription_scheme .ccp_display_disable_end_cancellation').hide(); 100 101 $('#woocommerce-product-data .add_subscription_scheme').on('click', function() { 102 $('#wcsatt_data').on('woocommerce_subscription_scheme_added', function(event, response) { 103 var $newScheme = response.$scheme || $('.subscription_schemes .subscription_scheme').last(); 104 105 $newScheme.find('.ccp_cancellation_window_box').hide(); 106 $newScheme.find('.ccp_display_disable_end_cancellation').hide(); 107 $newScheme.find('.ccp_cancellation_window_action_options').hide(); 108 $newScheme.find('.ccp_minimum_period_options').hide(); 109 $newScheme.find('.ccp_cancellation_settlement_fields').hide(); 110 }); 111 }); 112 113 // For Product Area (Custom Subscription Plan) 114 $( ".subscription_schemes .subscription_scheme" ).each(function() { 115 var $schemeBox = $(this); 116 117 var $selectedRadio = $schemeBox.find('input[name^="wcsatt_schemes"][name$="[scn_button_behaviour]"]:checked'); 118 119 if ($selectedRadio.length) { 120 if ($selectedRadio.val() === 'cancellation-rules') { 121 $schemeBox.find('.scn_notice').show(); 122 $schemeBox.find('.ccp_cancellation_window_box').show(); 123 } else if ($selectedRadio.val() === '') { 124 $schemeBox.find('.scn_notice').hide(); 125 $schemeBox.find('.ccp_cancellation_window_box').hide(); 126 } 127 } 128 }); 129 130 // For Woocommerce > Subscription Area (Global Subscription Plan) START 131 $( ".woocommerce_page_wc-settings .subscription_schemes .subscription_scheme" ).each(function() { 132 var $schemeBox = $(this); 133 var $selectedRadio = $schemeBox.find('input[name^="wcsatt_schemes"][name$="[scn_button_behaviour]"]:checked'); 134 135 if ($selectedRadio.length) { 136 if ($selectedRadio.val() === 'cancellation-rules') { 137 $schemeBox.find('.scn_notice').show(); 138 $schemeBox.find('.ccp_cancellation_window_box').show(); 139 }else{ 140 $schemeBox.find('.scn_notice').hide(); 141 $schemeBox.find('.ccp_cancellation_window_box').hide(); 142 } 143 } 144 145 if (!$selectedRadio.length) { 146 if ( typeof $selectedRadio.val() == 'undefined' ) { 147 $schemeBox.find('.scn_notice').hide(); 148 $schemeBox.find('.ccp_cancellation_window_box').hide(); 149 } 150 } 151 }); 152 153 $('body').on('change', '[id^="_ccp_cancellation_window_action"]', function () { 154 let $container = $(this).closest('.subscription_scheme_global_data'); 155 156 if ($(this).val() === '') { 157 $container.find('.ccp_cancellation_window_action_options').css({"display": "none"}); 158 $container.find('.ccp_cancellation_window_action_options').css({"flex-direction": "column"}); 159 $container.find('.ccp_cancellation_window_action_anytime').css({"display": "inline-flex"}); 160 } else { 161 $container.find('.ccp_cancellation_window_action_options').css({"display": "inline-flex"}); 162 $container.find('.ccp_cancellation_window_action_options').css({"flex-direction": "column"}); 163 $container.find('.ccp_cancellation_window_action_anytime').css({"display": "none"}); 164 } 165 }); 166 167 $('body').on('change', '[id^="_ccp_minimum_period"]', function () { 168 let $container = $(this).closest('.subscription_scheme_global_data'); 169 170 if (1 < $(this).val() ) { 171 $container.find('.ccp_minimum_period_options').css({"display": "inline-flex", "flex-direction": "column", "row-gap": "15px"}); 172 } else { 173 $container.find('.ccp_minimum_period_options').css({"display": "none"}); 174 } 175 176 } ); 177 178 $('.woocommerce_page_wc-settings .add_subscription_scheme').on('click', function() { 179 $('#wcsatt_data').on('woocommerce_subscription_scheme_added', function(event, response) { 180 // Target only the newly added subscription scheme 181 var $newScheme = response.$scheme || $('.woocommerce_page_wc-settings .subscription_schemes .subscription_scheme').last(); 182 $newScheme.find('.ccp_cancellation_window_box').hide(); 183 $newScheme.find('.ccp_display_disable_end_cancellation').hide(); 184 $newScheme.find('.ccp_cancellation_window_action_options').hide(); 185 $newScheme.find('.ccp_minimum_period_options').hide(); 186 $newScheme.find('.ccp_cancellation_settlement_fields').hide(); 187 }); 188 }); 189 // For Woocommerce > Subscription Area (Global Subscription Plan) END 190 191 // Cancellation Fee 192 //Single Product 193 $('#general_product_data .ccp_cancellation_period [id^="_ccp_enable_cancellation_fee"]').on('change', function () { 194 $(this).closest('.ccp_cancellation_period').find('.ccp_cancellation_fee_fields').toggle(this.checked); 195 }).trigger('change'); 196 197 198 // Cancellation Type 199 $('body').on('change', '#_ccp_cancellation_fee_type', function () { 200 var $val = $(this).val(); 201 if ($val === 'fixed') { 202 $('#_ccp_cancellation_fee_amount').val(10); 203 } else { 204 $('#_ccp_cancellation_fee_amount').val($val); 205 } 206 }); 207 208 //Variable Product 209 $(document).on('change', 'input[name^="_ccp_enable_cancellation_fee["]', function() { 210 var $variationBox = $(this).closest('.woocommerce_variation'); 211 var selected = $variationBox.find('input[name^="_ccp_enable_cancellation_fee["]:checked').val(); 212 213 $variationBox.find('.ccp_cancellation_fee_fields').hide(); 214 215 if (selected == 'yes') { 216 $variationBox.find('.ccp_cancellation_fee_fields').show(); 217 } 218 }); 219 220 $(document).on('change', 'select[name^="_ccp_cancellation_fee_type["]', function() { 221 var $variationBox = $(this).closest('.woocommerce_variation'); 222 var selected_fee_type = $(this).val(); // get directly from the changed dropdown 223 224 if (selected_fee_type === 'fixed') { 225 $variationBox.find('[id^="_ccp_cancellation_fee_amount["]').val(10); 226 }else{ 227 $variationBox.find('[id^="_ccp_cancellation_fee_amount["]').val(0); 228 } 229 }); 230 231 //WCSATT Products 232 $(document).on('change', '.subscription_schemes input[name^="wcsatt_schemes"][name$="[ccp_enable_cancellation_fee]"]', function() { 233 var $schemeBox = $(this).closest('.subscription_scheme'); 234 235 $schemeBox.find('.ccp_cancellation_fee_fields').hide(); 236 237 if ($(this).is(':checked')) { 238 $schemeBox.find('.ccp_cancellation_fee_fields').show(); 239 } 240 }); 241 242 // Works for dynamically loaded variation/scheme fields for WCSATT Products 243 $(document).on('change', '.subscription_scheme select[name^="wcsatt_schemes"][name$="[ccp_cancellation_fee_type]"]', function() { 244 245 var $schemeBox = $(this).closest('.subscription_scheme'); 246 var selected_fee_type = $(this).val(); 247 248 // Target the correct amount input inside this scheme box only 249 var $amountField = $schemeBox.find('input[name^="wcsatt_schemes"][name$="[ccp_cancellation_fee_amount]"]'); 250 251 if (selected_fee_type === 'fixed') { 252 $amountField.val(10); 253 } else { 254 $amountField.val(0); 255 } 256 }); 257 // Cancellation Fee 258 259 // Cancellation Settlement Start 260 //Single Product 261 $('#general_product_data .ccp_cancellation_period [id^="_ccp_enable_cancellation_settlement"]').on('change', function () { 262 $(this).closest('.ccp_cancellation_period').find('.ccp_cancellation_settlement_fields').toggle(this.checked); 263 }).trigger('change'); 264 265 //Variable Product 266 $(document).on('change', 'input[name^="_ccp_enable_cancellation_settlement["]', function() { 267 var $variationBox = $(this).closest('.woocommerce_variation'); 268 var selected = $variationBox.find('input[name^="_ccp_enable_cancellation_settlement["]:checked').val(); 269 270 $variationBox.find('.ccp_cancellation_settlement_fields').hide(); 271 272 if (selected == 'yes') { 273 $variationBox.find('.ccp_cancellation_settlement_fields').show(); 274 } 275 }); 276 277 //WCSATT Products 278 $(document).on('change', '.subscription_schemes input[name^="wcsatt_schemes"][name$="[ccp_enable_cancellation_settlement]"]', function() { 279 var $schemeBox = $(this).closest('.subscription_scheme'); 280 281 $schemeBox.find('.ccp_cancellation_settlement_fields').hide(); 282 283 if ($(this).is(':checked')) { 284 $schemeBox.find('.ccp_cancellation_settlement_fields').show(); 285 } 286 }); 287 288 // Cancellation Settlement End 289 290 /** 291 * SINMPLE SUBSCRIPTIONS 292 293 if ( 2 > $('#_ccp_minimum_period').val() ) { 294 $('#_ccp_minimum_period').parent().siblings("._ccp_cooling_off_period_field").css({"display": "none"}); 295 $('#_ccp_minimum_period').parent().siblings("._ccp_rolling_cycle_field").css({"display": "none"}); 296 $('#_ccp_minimum_period').parent().siblings("._ccp_disbale_end_cancellation_field ").css({"display": "none"}); 297 $('#_ccp_minimum_period').parent().siblings("._ccp_cancel_message_field").css({"display": "none"}); 298 $('#_ccp_minimum_period').parent().siblings("._ccp_suspend_button_field ").css({"display": "none"}); 299 $('#_ccp_minimum_period').parent().siblings("._ccp_switch_button_field").css({"display": "none"}); 300 } 301 302 $('body').on('change', '#_ccp_cancellation_window_action', function () { 303 if ('' == $(this).val() ) { 304 $(this).siblings().css({"display": "none"}); 305 } else { 306 $(this).siblings().css({"display": "flex"}); 307 } 308 309 } ); 310 $('body').on('change', '#_ccp_minimum_period', function () { 311 if (1 < $(this).val() ) { 312 $(this).parent().siblings("._ccp_cooling_off_period_field").css({"display": "block"}); 313 $(this).parent().siblings("._ccp_rolling_cycle_field").css({"display": "block"}); 314 $(this).parent().siblings("._ccp_cancel_message_field").css({"display": "block"}); 315 $(this).parent().siblings("._ccp_suspend_button_field ").css({"display": "block"}); 316 $(this).parent().siblings("._ccp_switch_button_field").css({"display": "block"}); 317 if (1 > $(this).parent().siblings("._ccp_rolling_cycle_field").children('#_ccp_rolling_cycle').val()){ 318 $(this).parent().siblings("._ccp_disbale_end_cancellation_field ").css({"display": "block"}); 319 } 320 321 } else { 322 $(this).parent().siblings("._ccp_cooling_off_period_field").css({"display": "none"}); 323 $(this).parent().siblings("._ccp_rolling_cycle_field").css({"display": "none"}); 324 $(this).parent().siblings("._ccp_disbale_end_cancellation_field ").css({"display": "none"}); 325 $(this).parent().siblings("._ccp_cancel_message_field").css({"display": "none"}); 326 $(this).parent().siblings("._ccp_suspend_button_field ").css({"display": "none"}); 327 $(this).parent().siblings("._ccp_switch_button_field").css({"display": "none"}); 328 } 329 330 } ); 331 $('body').on('change', '#_ccp_rolling_cycle', function () { 332 if (('' == $(this).val()) && (1 < $(this).val())) { 333 $(this).parent().siblings("._ccp_disbale_end_cancellation_field ").css({"display": "block"}); 334 } else { 335 $(this).parent().siblings("._ccp_disbale_end_cancellation_field ").css({"display": "none"}); 336 } 337 338 } ); 339 */ 340 //Hide cancellation rules fields on variable products 341 if ($('#product-type').val() == 'variable') { 342 $('.woocommerce_variations .ccp_variable').css('display', 'none'); 343 $(document).on('click', '.variations_tab a', function() { 344 $('#woocommerce-product-data').on('woocommerce_variations_loaded', function(event, response) { 345 $('.woocommerce_variations .ccp_variable').css('display', 'none'); 346 }); 347 }); 348 } 349 $('#product-type').on('change', function() { 350 if ($(this).val() == 'variable') { 351 $('.woocommerce_variations .ccp_variable').css('display', 'none'); 352 } 353 }); 354} ); 355 356jQuery(document).ready(function($) { 357 // Look inside subscription details table for cancel links 358 $('table.subscription_details a.cancel').each(function() { 359 var $btn = $(this); 360 var text = $btn.text().trim(); 361 362 // If the button label contains "Cancel from" 363 if (text.indexOf('Cancel from') !== -1) { 364 // Add disabled class 365 $btn.addClass('disabled-btn'); 366 367 // Optional: prevent clicks 368 $btn.on('click', function(e) { 369 e.preventDefault(); 370 return false;
371 }); 372 } 373 }); 374});
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.