1jQuery(function( $ ) { 2 //Get start date label 3 // var start_label = $("#_wscsd_start_label").val(); 4 // if(!start_label){ 5 // $(".wscsd_hide_date_options").css("display", "none"); 6 // } 7 //Check if dates are already exist otherwise hide the field 8 /* 9 var wscsd_fixed_start_dates_save = $(".wscsd_fixed_start_dates_save").val(); 10 if( wscsd_fixed_start_dates_save ){ 11 $(".wscsd_label").css("display", "block"); 12 } 13 */ 14 //Display options when a custom start is selected 15 $("#_wscsd_delay_type").change(function(){ 16 $(".wscsd_delay_additional_options").css("display", "none"); 17 var str = $("#_wscsd_delay_type").val(); 18 19 if( ( !str ) || ( 'no_delay' == str ) ) { 20 $(".wscsd_hide_date").css("display", "none"); 21 $(".wscsd_cut_off").css("display", "none"); 22 $(".wscsd_max_dates").css("display", "none"); 23 $(".wscsd_label").css("display", "none"); 24 $(".wscsd_cut_off_max").css("display", "none"); 25 $(".wscsd_delay_payment").css("display", "none"); 26 27 } else { 28 $(".wscsd_delay_payment").css("display", "block"); 29 if( str == 'delay') { 30 //Show the start date label (wscsd_hide_date_options) field 31 $(".wscsd_hide_date_options").css("display", "block"); 32 $(".wscsd_hide_date").css("display", "none"); 33 $(".wscsd_label").css("display", "block"); 34 $(".wscsd_cut_off").css("display", "none"); 35 $(".wscsd_max_dates").css("display", "none"); 36 $(".wscsd_cut_off_max").css("display", "none"); 37 } else if( str == 'fixed' ){ 38 //Show the start date label (wscsd_hide_date_options) field 39 $(".wscsd_hide_date_options").css("display", "block"); 40 $(".wscsd_hide_date").css("display", "block"); 41 $(".wscsd_cut_off").css("display", "block"); 42 $(".wscsd_max_dates").css("display", "block"); 43 $(".wscsd_cut_off_max").css("display", "none"); 44 } else { 45 $(".wscsd_hide_date").css("display", "none"); 46 $(".wscsd_label").css("display", "block"); 47 $(".wscsd_max_dates").css("display", "none"); 48 $(".wscsd_cut_off").css("display", "block"); 49 $(".wscsd_cut_off_max").css("display", "block"); 50 } 51 } 52 $(".wscsd_"+str).css("display", "block"); 53 }); 54 55 56 //Display date options 57 $("#_wscsd_hide_date").click(function(){ 58 $(".wscsd_hide_date_options").css("display", "block"); 59 if($("#_wscsd_hide_date").prop("checked") == false) { 60 $(".wscsd_hide_date_options").css("display", "block"); 61 $(".wscsd_max_dates").css("display", "block"); 62 $(".wscsd_label").css("display", "block"); 63 } else { 64 $(".wscsd_hide_date_options").css("display", "none"); 65 $(".wscsd_max_dates").css("display", "none"); 66 $(".wscsd_label").css("display", "none"); 67 } 68 }); 69 70 /***** 71 Fixed dates 72 ******/ 73 //Add dates (Simple Subscription) 74 $('body').on('click', '#_wscsd_fixed_start_dates_add', function(){ 75 var start_date = $(this).parent().siblings("#_wscsd_fixed_start_dates_field").val(); 76 if ($(this).closest('.wscsd_fixed').children('.wscsd_fixed_start_dates_save').val().indexOf(start_date) < 0) { 77 // // Convert to m-d-y format 78 var dateObj = new Date(start_date); 79 var mm = String(dateObj.getMonth() + 1).padStart(2, '0'); 80 var dd = String(dateObj.getDate()).padStart(2, '0'); 81 var yyyy = dateObj.getFullYear(); 82 var formatted_start_date = mm + '-' + dd + '-' + yyyy; 83 $(this).closest('._wscsd_fixed_start_dates_field_field').siblings("#_wscsd_fixed_start_dates_display").append("<span class='wscsd_fixed_start_date'><span class='wscsd_fixed_start_date_data'>"+formatted_start_date+"</span><span class='wscsd_fixed_start_date_delete'> X </span></span>"); 84 $(this).closest('.wscsd_fixed').children('.wscsd_fixed_start_dates_save').val($(this).closest('.wscsd_fixed').children('.wscsd_fixed_start_dates_save').val() + start_date + '|'); 85 $(this).parent().siblings("#_wscsd_fixed_start_dates_field").val(''); 86 } 87 }); 88 //Delete dates 89 $('body').on('click', '.wscsd_fixed_start_date_delete', function(){ 90 var date_value = $(this).closest('.wscsd_fixed_start_date').children('.wscsd_fixed_start_date_data').html(); 91 // Convert to Y-m-d format 92 var dateObj = new Date(date_value); 93 var mm = String(dateObj.getMonth() + 1).padStart(2, '0'); 94 var dd = String(dateObj.getDate()).padStart(2, '0'); 95 var yyyy = dateObj.getFullYear(); 96 var formatted_start_date = yyyy + '-' + mm + '-' + dd; 97 var date_to_delete = formatted_start_date + '|'; 98 $('#_wscsd_fixed_start_dates_save').val($('#_wscsd_fixed_start_dates_save').val().replace(date_to_delete, '')); 99 //variation 100 var var_old_dates = $(this).closest('.wscsd_variation').children('.wscsd_fixed_start_dates_save').val(); 101 if ( (var_old_dates) && (var_old_dates.length > 0) ) { 102 $(this).closest('.wscsd_variation').children('.wscsd_fixed_start_dates_save').val($(this).closest('.wscsd_variation').children('.wscsd_fixed_start_dates_save').val().replace(date_to_delete, '')); 103 $( this ).closest( '.woocommerce_variation' ).addClass( 'variation-needs-update' ); 104 $( 'button.cancel-variation-changes, button.save-variation-changes' ).prop( 'disabled', false ); 105 } 106 //end variation 107 $(this).closest('.wscsd_fixed_start_date').remove(); 108 }); 109 //Delete all dates (Simple Subscription) 110 $('body').on('click', '.wscsd_fixed_start_dates_deleteall', function(){ 111 $(this).closest('.wscsd_fixed').children('.wscsd_fixed_start_dates_save').val(''); 112 $(this).siblings("#_wscsd_fixed_start_dates_display").children('.wscsd_fixed_start_date').remove(); 113 $( this ).closest( '.woocommerce_variation' ).addClass( 'variation-needs-update' ); 114 $( 'button.cancel-variation-changes, button.save-variation-changes' ).prop( 'disabled', false ); 115 }); 116 117 /***** 118 Fixed delays
119 ******/ 120 //Add dates 121 $('body').on('click', '#_wscsd_fixed_delays_add', function(){ 122 var start_delay = $(this).parent().siblings("#_wscsd_fixed_delay_field").val() + ' ' + $(this).parent().siblings("#_wscsd_fixed_delay_period").val(); 123 if($(this).parent().siblings("#_wscsd_fixed_delay_field").val()){ 124 if ($(this).closest('.wscsd_delay').children('.wscsd_fixed_delays_save').val().indexOf(start_delay) < 0) { 125 $(this).closest('.form-field').siblings("#_wscsd_fixed_delays_display").append("<span class='wscsd_fixed_delay'><span class='wscsd_fixed_delay_data'>"+start_delay+"</span><span class='wscsd_fixed_delay_delete'> X </span></span>"); 126 $(this).closest('.wscsd_delay').children('.wscsd_fixed_delays_save').val($(this).closest('.wscsd_delay').children('.wscsd_fixed_delays_save').val() + start_delay + '|'); 127 $(this).parent().siblings('#_wscsd_fixed_delay_field').val(''); 128 } 129 } 130 }); 131 //Delete dates 132 $('body').on('click', '.wscsd_fixed_delay_delete', function(){ 133 var delay_to_delete = $(this).closest('.wscsd_fixed_delay').children('.wscsd_fixed_delay_data').html() + '|'; 134 //$('#_wscsd_fixed_delays_save').val($('#_wscsd_fixed_delays_save').val() + delay_to_delete + '|'); 135 $('#_wscsd_fixed_delays_save').val($('#_wscsd_fixed_delays_save').val().replace(delay_to_delete, '')); 136 //variation 137 var var_old_delay = $(this).closest('.wscsd_variation').children('.wscsd_fixed_delays_save').val(); 138 if ( (var_old_delay) && (var_old_delay.length > 0) ) { 139 $(this).closest('.wscsd_variation').children('.wscsd_fixed_delays_save').val($(this).closest('.wscsd_variation').children('.wscsd_fixed_delays_save').val().replace(delay_to_delete, '')); 140 $( this ).closest( '.woocommerce_variation' ).addClass( 'variation-needs-update' ); 141 $( 'button.cancel-variation-changes, button.save-variation-changes' ).prop( 'disabled', false ); 142 } 143 144 //end variation 145 $(this).closest('.wscsd_fixed_delay').remove(); 146 }); 147 //Delete all dates (Fixed delays Field) 148 $('body').on('click', '.wscsd_fixed_delays_deleteall', function(){ 149 $(this).closest('.wscsd_delay').children('.wscsd_fixed_delays_save').val(''); 150 $(this).siblings("#_wscsd_fixed_delays_display").children('.wscsd_fixed_delay').remove(); 151 $( this ).closest( '.woocommerce_variation' ).addClass( 'variation-needs-update' ); 152 $( 'button.cancel-variation-changes, button.save-variation-changes' ).prop( 'disabled', false ); 153 }); 154 155 /***** 156 Calendar | Maximum Start Date show/hide on single product 157 ******/ 158 $('body').on('change', '#_wscsd_cut_off_max',function(){ 159 var max_cut = $("#_wscsd_cut_off_max").val(); 160 if( max_cut == '') { 161 $(this).closest('._wscsd_cut_off_max_field').siblings('.wscsd_cut_off_max_fixed_date').css("display", "none"); 162 $(this).closest('._wscsd_cut_off_max_field').siblings('.wscsd_cut_off_max_period').css("display", "none"); 163 } else if( max_cut == 'fixed_date') { 164 $(this).closest('._wscsd_cut_off_max_field').siblings('.wscsd_cut_off_max_fixed_date').css("display", "block"); 165 $(this).closest('._wscsd_cut_off_max_field').siblings('.wscsd_cut_off_max_period').css("display", "none"); 166 } else if( max_cut == 'period') { 167 $(this).closest('._wscsd_cut_off_max_field').siblings('.wscsd_cut_off_max_fixed_date').css("display", "none"); 168 $(this).closest('._wscsd_cut_off_max_field').siblings('.wscsd_cut_off_max_period').css("display", "block"); 169 } 170 }); 171 172 //Maximum Start Date show/hide on variation product 173 $('body').on('change', '[id^="_wscsd_cut_off_max["]', function(event) { 174 var variation_ID = (event.target.id).match(/\[(\d+)\]/); 175 variation_ID = variation_ID ? variation_ID[1] : ''; 176 var max_cut = $(this).val(); 177 178 // Build selector with escaped brackets 179 var $field = $('#_wscsd_cut_off_max_field\\[' + variation_ID + '\\]'); 180 181 if (max_cut === '') { 182 $field.find('.wscsd_cut_off_max_fixed_date, .wscsd_cut_off_max_period').hide(); 183 } else if (max_cut === 'fixed_date') { 184 $field.find('.wscsd_cut_off_max_fixed_date').show(); 185 $field.find('.wscsd_cut_off_max_period').hide(); 186 } else if (max_cut === 'period') { 187 $field.find('.wscsd_cut_off_max_fixed_date').hide(); 188 $field.find('.wscsd_cut_off_max_period').show(); 189 } 190 }); 191 192 //VARIATIONS 193 $('body').on('change', '[id^="_wscsd_delay_type"]', function(event) { 194 var variation_ID = '\[' + (event.target.id).split("[").pop(); 195 if ( ( variation_ID ) && ( 0 < variation_ID.length ) ) { 196 var delay_type = $(document.getElementById("_wscsd_delay_type" + variation_ID )).val(); 197 $(document.getElementById("_wscsd_fixed" + variation_ID )).css("display", "none"); 198 $(document.getElementById("_wscsd_delay" + variation_ID )).css("display", "none"); 199 $(document.getElementById("_wscsd_delay_payment" + variation_ID )).css("display", "none"); 200 201 if( ( !delay_type ) || ( 'no_delay' == delay_type ) || ( 'product_default' == delay_type ) ) { 202 $(document.getElementById("_wscsd_hide_date_options" + variation_ID )).css("display", "none"); 203 $(document.getElementById("_wscsd_cut_off_field" + variation_ID )).css("display", "none"); 204 $(document.getElementById("_wscsd_max_dates_field" + variation_ID )).css("display", "none"); 205 $(document.getElementById("_wscsd_start_date_label" + variation_ID )).css("display", "none"); 206 $(document.getElementById("_wscsd_start_date_label_display" + variation_ID )).css("display", "none"); 207 $(document.getElementById("_wscsd_delay_payment" + variation_ID )).css("display", "none"); 208 $(document.getElementById("_wscsd_cut_off_max_field" + variation_ID )).css("display", "none"); 209 } else { 210 $(document.getElementById("_wscsd_delay_payment" + variation_ID )).css("display", "block"); 211 if( delay_type == 'delay') { 212 $(document.getElementById("_wscsd_hide_date_options" + variation_ID )).css("display", "none"); 213 $(document.getElementById("_wscsd_cut_off_field" + variation_ID )).css("display", "none"); 214 $(document.getElementById("_wscsd_start_date_label" + variation_ID )).css("display", "block"); 215 $(document.getElementById("_wscsd_start_date_label_display" + variation_ID )).css("display", "block"); 216 $(document.getElementById("_wscsd_max_dates_field" + variation_ID )).css("display", "none"); 217 $(document.getElementById("_wscsd_cut_off_max_field" + variation_ID )).css("display", "none"); 218 } else if( delay_type == 'fixed' ){ 219 $(document.getElementById("_wscsd_hide_date_options" + variation_ID )).css("display", "block"); 220 $(document.getElementById("_wscsd_cut_off_field" + variation_ID )).css("display", "block"); 221 $(document.getElementById("_wscsd_start_date_label" + variation_ID )).css("display", "block"); 222 $(document.getElementById("_wscsd_start_date_label_display" + variation_ID )).css("display", "block"); 223 $(document.getElementById("_wscsd_max_dates_field" + variation_ID )).css("display", "block"); 224 $(document.getElementById("_wscsd_cut_off_max_field" + variation_ID )).css("display", "none"); 225 } else { 226 $(document.getElementById("_wscsd_hide_date_options" + variation_ID )).css("display", "none"); 227 $(document.getElementById("_wscsd_start_date_label" + variation_ID )).css("display", "block"); 228 $(document.getElementById("_wscsd_start_date_label_display" + variation_ID )).css("display", "block"); 229 $(document.getElementById("_wscsd_max_dates_field" + variation_ID )).css("display", "none"); 230 $(document.getElementById("_wscsd_cut_off_field" + variation_ID )).css("display", "block"); 231 $(document.getElementById("_wscsd_delay_payment" + variation_ID )).css("display", "block"); 232 $(document.getElementById("_wscsd_cut_off_max_field" + variation_ID )).css("display", "block"); 233 } 234 } 235 $(document.getElementById("_wscsd_" + delay_type + variation_ID)).css("display", "block"); 236 } 237 }); 238 239 //Display date options 240 $('body').on('click', '[id^="_wscsd_hide_date"]', function(event) { 241 var variation_ID = '\[' + (event.target.id).split("[").pop(); 242 if ( ( variation_ID ) && ( 0 < variation_ID.length ) ) { 243 if($(document.getElementById("_wscsd_hide_date" + variation_ID )).prop("checked") == false) { 244 $(document.getElementById("_wscsd_max_dates_field" + variation_ID )).css("display", "block"); 245 $(document.getElementById("_wscsd_start_date_label" + variation_ID )).css("display", "block"); 246 $(document.getElementById("_wscsd_start_date_label_display" + variation_ID )).css("display", "block"); 247 } else { 248 $(document.getElementById("_wscsd_max_dates_field" + variation_ID )).css("display", "none"); 249 $(document.getElementById("_wscsd_start_date_label" + variation_ID )).css("display", "none"); 250 $(document.getElementById("_wscsd_start_date_label_display" + variation_ID )).css("display", "none"); 251 } 252 } 253 }); 254 255 /***** 256 Fixed dates 257 ******/ 258 //Add dates (Variable Subscription) 259 $('body').on('click', '[id^="_wscsd_fixed_start_dates_add"]', function(event){ 260 var variation_ID = '\[' + (event.target.id).split("[").pop(); 261 if ( ( variation_ID ) && ( 0 < variation_ID.length ) ) { 262 var start_date = $(document.getElementById("_wscsd_fixed_start_dates_field" + variation_ID )).val(); 263 if ( start_date && $(document.getElementById("_wscsd_fixed_start_dates_save" + variation_ID )).val().indexOf(start_date) == -1 ) { 264 // Convert to m-d-y format 265 var dateObj = new Date(start_date); 266 var mm = String(dateObj.getMonth() + 1).padStart(2, '0'); 267 var dd = String(dateObj.getDate()).padStart(2, '0'); 268 var yyyy = dateObj.getFullYear(); 269 var formatted_start_date = mm + '-' + dd + '-' + yyyy; 270 $(document.getElementById("_wscsd_fixed_start_dates_display" + variation_ID )).append("<span class='wscsd_fixed_start_date'><span class='wscsd_fixed_start_date_data'>"+formatted_start_date+"</span><span class='wscsd_fixed_start_date_delete'> X </span></span>"); 271 $(document.getElementById("_wscsd_fixed_start_dates_save" + variation_ID )).val($(this).closest('.wscsd_fixed').children('.wscsd_fixed_start_dates_save').val() + start_date + '|'); 272 $(document.getElementById("_wscsd_fixed_start_dates_field" + variation_ID )).val(''); 273 } 274 } 275 }); 276 //Delete all dates (Variable Subscription) 277 $('body').on('click', '[id^="_wscsd_fixed_start_dates_deleteall"]', function(event){ 278 var variation_ID = '\[' + (event.target.id).split("[").pop(); 279 if ( ( variation_ID ) && ( 0 < variation_ID.length ) ) { 280 $(document.getElementById("_wscsd_fixed" + variation_ID)).children('.wscsd_fixed_start_dates_save').val(''); 281 $(document.getElementById("_wscsd_fixed_start_dates_display" + variation_ID)).children('.wscsd_fixed_start_date').remove(); 282 } 283 }); 284 //end variation 285 286if( $("table.variations" ).length == 1 ){ 287 $( ".single_variation_wrap" ).on( "show_variation", function ( event, variation ) { 288 // Fired when the user selects all the required dropdowns / attributes 289 // and a final variation is selected / shown 290 //Show further only if wcsatt is disabled 291 if( $('.wcsatt-options-wrapper-grouped').length == 0 ){ 292 $(variation.start_date_display).insertAfter(".woocommerce-variation-description"); 293 294 if ($('.wscsd_date_picker').length > 0) { 295 $('.wscsd_date_picker').css('display', 'none'); 296 if ($('.wcsatt-options-wrapper').css('display') == 'none') { 297 $('.wscsd_date_picker').css('display', ''); 298 }else{ 299 var customDatePicker = $('.wscsd_date_picker'); //Store the custom date options 300 customDatePicker.hide(); //Hide the custom date options 301 var csdatePicker = $(customDatePicker).detach(); //Detach the custom date options but save its elements and events 302 303 $(csdatePicker).insertAfter(".woocommerce-variation-description").show(); 304 305 //Show the custom date option as per wcsatt radio selection. 306 $('.wcsatt-options-prompt-label input[type="radio"]').on('change', function() { 307 // Check if the subscription radio button is checked 308 if ($('.wcsatt-options-prompt-label-subscription input[type="radio"]:checked').length > 0) { 309 // Append the custom date 310 $(csdatePicker).appendTo($('.wcsatt-options-wrapper')).show(); 311 } 312 // Check if the one-time radio button is checked 313 else if ($('.wcsatt-options-prompt-label-one-time input[type="radio"]:checked').length > 0) { 314 // Detach the custom date again 315 $(customDatePicker).detach(); 316 } 317 }); 318 } 319 } 320 } 321 } ).on('hide_variation', function(event) { 322 $('.wscsd_date_picker').remove(); 323 }); 324} 325 326 327 // Make sure start date picker is in the past 328 $( '.woocommerce-subscriptions.date-picker.hasDatepicker#start' ).datepicker( 'option', 'maxDate', null ); 329 330 // Make sure start date is before now on change js in assets/js/admin/meta-boxes-subscription.js?ver=6.9.2 331 332 //Hide start date 333 $( "#subscription-wscsd-start-date" ).filter(function() { 334 return $(this).next("#subscription-start-date").css("display", "none"); 335 }); 336 337 //Ensure the WSCSD fields will appear on Simple Subscription General Tab if All Product for Woocommerce Subscription is disabled 338 $(document).on('click', '.general_tab a', function() { 339 if ($('#product-type').val() == 'subscription') { 340 $('.wscsd_custom_start_date.show_if_subscription').css('display', 'block'); 341 $('.wscsd_custom_start_date.show_if_subscription').css('min-height', 'auto'); 342 $('.wscsd_custom_start_date.show_if_subscription').css('float', 'right'); 343 $('.wscsd_custom_start_date.show_if_subscription').css('width', 'revert-layer'); 344 345 $('.woocommerce_options_panel.wscsd_custom_start_date').css('display', 'block'); 346 $('.woocommerce_options_panel.wscsd_custom_start_date').css('min-height', 'auto'); 347 $('.woocommerce_options_panel.wscsd_custom_start_date').css('float', 'right'); 348 $('.woocommerce_options_panel.wscsd_custom_start_date').css('width', 'revert-layer'); 349 } 350 });
351 if ($('#product-type').val() == 'subscription') { 352 $('.wscsd_custom_start_date.show_if_subscription').css('display', 'block'); 353 $('.wscsd_custom_start_date.show_if_subscription').css('min-height', 'auto'); 354 $('.wscsd_custom_start_date.show_if_subscription').css('float', 'right'); 355 $('.wscsd_custom_start_date.show_if_subscription').css('width', 'revert-layer'); 356 } 357 if ($('#product-type').val() == 'variable-subscription'){ 358 $(document).on('click', '.variations_tab a', function() { 359 $('#woocommerce-product-data').on('woocommerce_variations_loaded', function(event, response) { 360 $('.wscsd_variations_box').css('display', 'block'); 361 $('[id^="_wscsd_delay_type"]').each(function() { 362 var $this = $(this); 363 var delayType = $this.val(); 364 365 // Scope to the current variation group 366 var $group = $this.closest('.wscsd_variations_box'); 367 368 // Scoped selectors (note the escaped '[') 369 var selectors = [ 370 '[id^="_wscsd_delay_payment\\["]', 371 '[id^="_wscsd_hide_date_options\\["]', 372 '[id^="_wscsd_start_date_label\\["]', 373 '[id^="_wscsd_start_date_label_display\\["]', 374 '[id^="_wscsd_fixed\\["]', 375 '[id^="_wscsd_delay\\["]', 376 '[id^="_wscsd_cut_off_field\\["]', 377 '[id^="_wscsd_cut_off_max_field\\["]' 378 ]; 379 380 var $targets = $group.find(selectors.join(',')); 381 382 if (delayType === 'no_delay' || delayType === 'product_default') { 383 //Hide all fields 384 $targets.hide(); 385 } else if (delayType === 'fixed') { 386 // Show everything first 387 $targets.show(); 388 //Hide or show max nb of date to display, Start date label & Show Start Date Label in Cart & Checkout 389 if($group.find('[id^="_wscsd_hide_date\\["]').is(':checked')){ 390 $group.find('[id^="_wscsd_start_date_label\\["]').hide(); 391 $group.find('[id^="_wscsd_max_dates_field\\["]').hide(); 392 $group.find('[id^="_wscsd_start_date_label_display\\["]').hide(); 393 }else{ 394 $group.find('[id^="_wscsd_start_date_label\\["]').show(); 395 $group.find('[id^="_wscsd_max_dates_field\\["]').show(); 396 $group.find('[id^="_wscsd_start_date_label_display\\["]').show(); 397 } 398 399 400 // Hide the delay field 401 $group.find('[id^="_wscsd_delay\\["]').hide(); 402 403 404 // Hide the maximum start date field 405 $group.find('[id^="_wscsd_cut_off_max_field\\["]').hide(); 406 } else if (delayType === 'delay') { 407 // Show everything first 408 $targets.show(); 409 410 // Hide the delay field 411 $group.find('[id^="_wscsd_hide_date_options\\["]').hide(); 412 413 // Hide the fixed start date field 414 $group.find('[id^="_wscsd_fixed\\["]').hide(); 415 416 //Hide the Cut off field 417 $group.find('[id^="_wscsd_cut_off_field\\["]').hide(); 418 419 // Hide the maximum start date field 420 $group.find('[id^="_wscsd_cut_off_max_field\\["]').hide(); 421 } else if (delayType === 'calendar') { 422 // Show everything first 423 $targets.show(); 424 425 // Maximum start date field 426 if($group.find('[id^="_wscsd_cut_off_max\\["]').val() == ''){ 427 $group.find('.wscsd_cut_off_max_fixed_date').hide(); 428 $group.find('.wscsd_cut_off_max_period').hide(); 429 }else if ($group.find('[id^="_wscsd_cut_off_max\\["]').val() == 'fixed_date'){ 430 $group.find('.wscsd_cut_off_max_fixed_date').show(); 431 $group.find('.wscsd_cut_off_max_period').hide(); 432 }else if ($group.find('[id^="_wscsd_cut_off_max\\["]').val() == 'period') { 433 $group.find('.wscsd_cut_off_max_fixed_date').hide(); 434 $group.find('.wscsd_cut_off_max_period').show(); 435 } 436 437 // Hide the delay field 438 $group.find('[id^="_wscsd_hide_date_options\\["]').hide(); 439 440 // Hide the fixed start date field 441 $group.find('[id^="_wscsd_fixed\\["]').hide(); 442 443 // Hide the delay field 444 $group.find('[id^="_wscsd_delay\\["]').hide(); 445 } 446 }); 447 }); 448 }); 449 } 450 451 //Check if All Product for woocommerce Subscription plugin is deactivated 452 if (document.querySelectorAll('ul.product_data_tabs li.satt_options').length == 0) { 453 // Monitor when a variation is saved 454 $('#variable_product_options').on('click', 'button.save-variation-changes', function() { 455 $('#woocommerce-product-data').on('woocommerce_variations_loaded', function(event, response) { 456 if($('#product-type').val() == 'variable-subscription') { 457 $('.wscsd_variations_box [id^="_wscsd_delay_type"]').each(function() { 458 var $this = $(this); 459 var delayType = $this.val(); 460 461 // Scope to the current variation group 462 var $group = $this.closest('.wscsd_variations_box'); 463 464 // Scoped selectors (note the escaped '[') 465 var selectors = [
466 '[id^="_wscsd_delay_payment\\["]', 467 '[id^="_wscsd_hide_date_options\\["]', 468 '[id^="_wscsd_start_date_label\\["]', 469 '[id^="_wscsd_start_date_label_display\\["]', 470 '[id^="_wscsd_fixed\\["]', 471 '[id^="_wscsd_delay\\["]', 472 '[id^="_wscsd_cut_off_field\\["]', 473 '[id^="_wscsd_cut_off_max_field\\["]' 474 ]; 475 476 var $targets = $group.find(selectors.join(',')); 477 478 if (delayType === 'no_delay' || delayType === 'product_default') { 479 //Hide all fields 480 $targets.hide(); 481 } else if (delayType === 'fixed') { 482 // Show everything first 483 $targets.show(); 484 //Max nb of date to display 485 $group.find('[id^="_wscsd_max_dates_field\\["]').show(); 486 487 // Hide the delay field 488 $group.find('[id^="_wscsd_delay\\["]').hide(); 489 490 491 // Hide the maximum start date field 492 $group.find('[id^="_wscsd_cut_off_max_field\\["]').hide(); 493 } else if (delayType === 'delay') { 494 // Show everything first 495 $targets.show(); 496 497 // Hide the delay field 498 $group.find('[id^="_wscsd_hide_date_options\\["]').hide(); 499 500 // Hide the fixed start date field 501 $group.find('[id^="_wscsd_fixed\\["]').hide(); 502 503 //Hide the Cut off field 504 $group.find('[id^="_wscsd_cut_off_field\\["]').hide(); 505 506 // Hide the maximum start date field 507 $group.find('[id^="_wscsd_cut_off_max_field\\["]').hide(); 508 } else if (delayType === 'calendar') { 509 // Show everything first 510 $targets.show(); 511 512 // Maximum start date field 513 if($group.find('[id^="_wscsd_cut_off_max\\["]').val() == ''){ 514 $group.find('.wscsd_cut_off_max_fixed_date').hide(); 515 $group.find('.wscsd_cut_off_max_period').hide(); 516 }else if ($group.find('[id^="_wscsd_cut_off_max\\["]').val() == 'fixed_date'){ 517 $group.find('.wscsd_cut_off_max_fixed_date').show(); 518 $group.find('.wscsd_cut_off_max_period').hide(); 519 }else if ($group.find('[id^="_wscsd_cut_off_max\\["]').val() == 'period') { 520 $group.find('.wscsd_cut_off_max_fixed_date').hide(); 521 $group.find('.wscsd_cut_off_max_period').show(); 522 } 523 524 // Hide the delay field 525 $group.find('[id^="_wscsd_hide_date_options\\["]').hide(); 526 527 // Hide the fixed start date field 528 $group.find('[id^="_wscsd_fixed\\["]').hide(); 529 530 // Hide the delay field 531 $group.find('[id^="_wscsd_delay\\["]').hide(); 532 } 533 }); 534 } 535 }); 536 }); 537 538 // Monitor when a variation is generated 539 $('#variable_product_options').on('click', 'button.generate_variations', function() { 540 541 // Monitor the variations table for changes (new rows added) 542 let initialRowCount = $('#variable_product_options .woocommerce_variations .woocommerce_variation').length; 543 544 // Check every 2 seconds if the number of variations has increased 545 let checkVariationsAdded = setInterval(function() { 546 let currentRowCount = $('#variable_product_options .woocommerce_variations .woocommerce_variation').length; 547 548 if (currentRowCount > initialRowCount) { 549 if($('#product-type').val() == 'variable-subscription') { 550 $('.wscsd_variations_box').css('display', 'block'); 551 $('.wscsd_variations_box [id^="_wscsd_delay_type"]').each(function() { 552 var $this = $(this); 553 var delayType = $this.val(); 554 555 // Scope to the current variation group 556 var $group = $this.closest('.wscsd_variations_box'); 557 558 // Scoped selectors (note the escaped '[') 559 var selectors = [ 560 '[id^="_wscsd_delay_payment\\["]', 561 '[id^="_wscsd_hide_date_options\\["]', 562 '[id^="_wscsd_start_date_label\\["]', 563 '[id^="_wscsd_start_date_label_display\\["]', 564 '[id^="_wscsd_fixed\\["]', 565 '[id^="_wscsd_delay\\["]', 566 '[id^="_wscsd_cut_off_field\\["]', 567 '[id^="_wscsd_cut_off_max_field\\["]' 568 ]; 569 570 var $targets = $group.find(selectors.join(',')); 571 572 if (delayType === 'no_delay' || delayType === 'product_default') { 573 //Hide all fields 574 $targets.hide(); 575 } else if (delayType === 'fixed') { 576 // Show everything first 577 $targets.show(); 578 //Max nb of date to display 579 $group.find('[id^="_wscsd_max_dates_field\\["]').show(); 580 581 // Hide the delay field 582 $group.find('[id^="_wscsd_delay\\["]').hide(); 583 584 585 // Hide the maximum start date field 586 $group.find('[id^="_wscsd_cut_off_max_field\\["]').hide(); 587 } else if (delayType === 'delay') { 588 // Show everything first 589 $targets.show(); 590 591 // Hide the delay field 592 $group.find('[id^="_wscsd_hide_date_options\\["]').hide(); 593 594 // Hide the fixed start date field 595 $group.find('[id^="_wscsd_fixed\\["]').hide(); 596 597 //Hide the Cut off field 598 $group.find('[id^="_wscsd_cut_off_field\\["]').hide(); 599 600 // Hide the maximum start date field 601 $group.find('[id^="_wscsd_cut_off_max_field\\["]').hide(); 602 } else if (delayType === 'calendar') { 603 // Show everything first 604 $targets.show(); 605 606 // Maximum start date field 607 if($group.find('[id^="_wscsd_cut_off_max\\["]').val() == ''){ 608 $group.find('.wscsd_cut_off_max_fixed_date').hide(); 609 $group.find('.wscsd_cut_off_max_period').hide(); 610 }else if ($group.find('[id^="_wscsd_cut_off_max\\["]').val() == 'fixed_date'){ 611 $group.find('.wscsd_cut_off_max_fixed_date').show(); 612 $group.find('.wscsd_cut_off_max_period').hide(); 613 }else if ($group.find('[id^="_wscsd_cut_off_max\\["]').val() == 'period') { 614 $group.find('.wscsd_cut_off_max_fixed_date').hide(); 615 $group.find('.wscsd_cut_off_max_period').show(); 616 } 617 618 // Hide the delay field 619 $group.find('[id^="_wscsd_hide_date_options\\["]').hide(); 620 621 // Hide the fixed start date field 622 $group.find('[id^="_wscsd_fixed\\["]').hide(); 623 624 // Hide the delay field 625 $group.find('[id^="_wscsd_delay\\["]').hide(); 626 } 627 });
628 } 629 clearInterval(checkVariationsAdded); 630 } 631 }, 2000); // 2-second interval 632 633 }); 634 635 // Monitor when a variation is added manually 636 $('#variable_product_options').on('click', 'button.add_variation_manually', function() { 637 638 // Monitor the variations table for changes (new rows added) 639 let initialRowCount = $('#variable_product_options .woocommerce_variations .woocommerce_variation').length; 640 641 // Check every 2 seconds if the number of variations has increased 642 let checkVariationsAdded = setInterval(function() { 643 let currentRowCount = $('#variable_product_options .woocommerce_variations .woocommerce_variation').length; 644 645 if (currentRowCount > initialRowCount) { 646 if($('#product-type').val() == 'variable-subscription') { 647 $('.wscsd_variations_box').css('display', 'block'); 648 $('.wscsd_variations_box [id^="_wscsd_delay_type"]').each(function() { 649 var $this = $(this); 650 var delayType = $this.val(); 651 652 // Scope to the current variation group 653 var $group = $this.closest('.wscsd_variations_box'); 654 655 // Scoped selectors (note the escaped '[') 656 var selectors = [ 657 '[id^="_wscsd_delay_payment\\["]', 658 '[id^="_wscsd_hide_date_options\\["]', 659 '[id^="_wscsd_start_date_label\\["]', 660 '[id^="_wscsd_start_date_label_display\\["]', 661 '[id^="_wscsd_fixed\\["]', 662 '[id^="_wscsd_delay\\["]', 663 '[id^="_wscsd_cut_off_field\\["]', 664 '[id^="_wscsd_cut_off_max_field\\["]' 665 ]; 666 667 var $targets = $group.find(selectors.join(',')); 668 669 if (delayType === 'no_delay' || delayType === 'product_default') { 670 //Hide all fields 671 $targets.hide(); 672 } else if (delayType === 'fixed') { 673 // Show everything first 674 $targets.show(); 675 //Max nb of date to display 676 $group.find('[id^="_wscsd_max_dates_field\\["]').show(); 677 678 // Hide the delay field 679 $group.find('[id^="_wscsd_delay\\["]').hide(); 680 681 682 // Hide the maximum start date field 683 $group.find('[id^="_wscsd_cut_off_max_field\\["]').hide(); 684 } else if (delayType === 'delay') { 685 // Show everything first 686 $targets.show(); 687 688 // Hide the delay field 689 $group.find('[id^="_wscsd_hide_date_options\\["]').hide(); 690 691 // Hide the fixed start date field 692 $group.find('[id^="_wscsd_fixed\\["]').hide(); 693 694 //Hide the Cut off field 695 $group.find('[id^="_wscsd_cut_off_field\\["]').hide(); 696 697 // Hide the maximum start date field 698 $group.find('[id^="_wscsd_cut_off_max_field\\["]').hide(); 699 } else if (delayType === 'calendar') { 700 // Show everything first 701 $targets.show(); 702 703 // Maximum start date field 704 if($group.find('[id^="_wscsd_cut_off_max\\["]').val() == ''){ 705 $group.find('.wscsd_cut_off_max_fixed_date').hide(); 706 $group.find('.wscsd_cut_off_max_period').hide(); 707 }else if ($group.find('[id^="_wscsd_cut_off_max\\["]').val() == 'fixed_date'){ 708 $group.find('.wscsd_cut_off_max_fixed_date').show(); 709 $group.find('.wscsd_cut_off_max_period').hide(); 710 }else if ($group.find('[id^="_wscsd_cut_off_max\\["]').val() == 'period') { 711 $group.find('.wscsd_cut_off_max_fixed_date').hide(); 712 $group.find('.wscsd_cut_off_max_period').show(); 713 } 714 715 // Hide the delay field 716 $group.find('[id^="_wscsd_hide_date_options\\["]').hide(); 717 718 // Hide the fixed start date field 719 $group.find('[id^="_wscsd_fixed\\["]').hide(); 720 721 // Hide the delay field 722 $group.find('[id^="_wscsd_delay\\["]').hide(); 723 } 724 }); 725 } 726 clearInterval(checkVariationsAdded); 727 } 728 }, 2000); // 2-second interval 729 730 }); 731 732 // Monitor when a variation is removed 733 $('#variable_product_options').on('click', 'a.remove_variation', function() { 734 735 // Monitor the variations table for changes (rows removed) 736 let initialRowCount = $('#variable_product_options .woocommerce_variations .woocommerce_variation').length; 737
738 // Check every 2 seconds if the number of variations has decreased 739 let checkVariationsRemoved = setInterval(function() { 740 let currentRowCount = $('#variable_product_options .woocommerce_variations .woocommerce_variation').length; 741 742 if (currentRowCount < initialRowCount) { 743 if($('#product-type').val() == 'variable-subscription') { 744 $('.wscsd_variations_box').css('display', 'block'); 745 $('.wscsd_variations_box [id^="_wscsd_delay_type"]').each(function() { 746 var delayType = $(this).val(); 747 if (delayType === 'no_delay') { 748 $(".wscsd_delay_additional_options").css("display", "none"); 749 } 750 }); 751 } 752 clearInterval(checkVariationsRemoved); 753 } 754 }, 2000); // 2-second interval 755 }); 756 757 $(document).on('click', '.variations_tab a', function() { 758 if ($('#product-type').val() == 'variable'){ 759 $('#woocommerce-product-data').on('woocommerce_variations_loaded', function(event, response) { 760 $('[id^="_wscsd_delay_type"]').each(function() { 761 var delayType = $(this).val(); 762 if (delayType === 'no_delay') { 763 $(".wscsd_delay_additional_options").css("display", "none"); 764 } 765 }); 766 }); 767 }else if ($('#product-type').val() == 'variable-subscription'){ 768 $('#woocommerce-product-data').on('woocommerce_variations_loaded', function(event, response) { 769 $('[id^="_wscsd_delay_type"]').each(function() { 770 var $this = $(this); 771 var delayType = $this.val(); 772 773 // Scope to the current variation group 774 var $group = $this.closest('.wscsd_variations_box'); 775 776 // Scoped selectors (note the escaped '[') 777 var selectors = [ 778 '[id^="_wscsd_delay_payment\\["]', 779 '[id^="_wscsd_hide_date_options\\["]', 780 '[id^="_wscsd_start_date_label\\["]', 781 '[id^="_wscsd_start_date_label_display\\["]', 782 '[id^="_wscsd_fixed\\["]', 783 '[id^="_wscsd_delay\\["]', 784 '[id^="_wscsd_cut_off_field\\["]', 785 '[id^="_wscsd_cut_off_max_field\\["]' 786 ]; 787 788 var $targets = $group.find(selectors.join(',')); 789 790 if (delayType === 'no_delay' || delayType === 'product_default') { 791 //Hide all fields 792 $targets.hide(); 793 } else if (delayType === 'fixed') { 794 // Show everything first 795 $targets.show(); 796 //Max nb of date to display 797 $group.find('[id^="_wscsd_max_dates_field\\["]').show(); 798 799 // Hide the delay field 800 $group.find('[id^="_wscsd_delay\\["]').hide(); 801 802 803 // Hide the maximum start date field 804 $group.find('[id^="_wscsd_cut_off_max_field\\["]').hide(); 805 } else if (delayType === 'delay') { 806 // Show everything first 807 $targets.show(); 808 809 // Hide the delay field 810 $group.find('[id^="_wscsd_hide_date_options\\["]').hide(); 811 812 // Hide the fixed start date field 813 $group.find('[id^="_wscsd_fixed\\["]').hide(); 814 815 //Hide the Cut off field 816 $group.find('[id^="_wscsd_cut_off_field\\["]').hide(); 817 818 // Hide the maximum start date field 819 $group.find('[id^="_wscsd_cut_off_max_field\\["]').hide(); 820 } else if (delayType === 'calendar') { 821 // Show everything first 822 $targets.show(); 823 824 // Maximum start date field 825 if($group.find('[id^="_wscsd_cut_off_max\\["]').val() == ''){ 826 $group.find('.wscsd_cut_off_max_fixed_date').hide(); 827 $group.find('.wscsd_cut_off_max_period').hide(); 828 }else if ($group.find('[id^="_wscsd_cut_off_max\\["]').val() == 'fixed_date'){ 829 $group.find('.wscsd_cut_off_max_fixed_date').show(); 830 $group.find('.wscsd_cut_off_max_period').hide(); 831 }else if ($group.find('[id^="_wscsd_cut_off_max\\["]').val() == 'period') { 832 $group.find('.wscsd_cut_off_max_fixed_date').hide(); 833 $group.find('.wscsd_cut_off_max_period').show(); 834 } 835 836 // Hide the delay field 837 $group.find('[id^="_wscsd_hide_date_options\\["]').hide(); 838 839 // Hide the fixed start date field 840 $group.find('[id^="_wscsd_fixed\\["]').hide(); 841 842 // Hide the delay field 843 $group.find('[id^="_wscsd_delay\\["]').hide(); 844 } 845 });
846 $('.wscsd_variations_box').css('display', 'block'); 847 }); 848 } 849 }); 850 851 if ($('#product-type').val() == 'variable-subscription') { 852 $('.wscsd_variations_box').css('display', 'block'); 853 $('.woocommerce_options_panel.wscsd_custom_start_date').css('display', 'none'); 854 $('.wscsd_variations_box').css('float', 'left'); 855 $('.wscsd_variations_box').css('width', '100%'); 856 } 857 if ($('#product-type').val() == 'variable') { 858 // $('.wscsd_variations_box').css('display', 'none'); 859 $('.wscsd_variations_box').remove(); 860 $('.woocommerce_options_panel.wscsd_custom_start_date').css('display', 'none'); 861 $('.wscsd_variations_box').css('float', 'left'); 862 $('.wscsd_variations_box').css('width', '100%'); 863 } 864 if ($('#product-type').val() == 'subscription') { 865 $('.wscsd_variations_box').css('display', 'none'); 866 $('.woocommerce_options_panel.wscsd_custom_start_date').css('display', 'block'); 867 $('.wscsd_variations_box').css('float', 'left'); 868 $('.wscsd_variations_box').css('width', '100%'); 869 } 870 871 $('#product-type').on('change', function() { 872 if ($(this).val() == 'variable') { 873 $('.wscsd_variations_box').css('display', 'none'); 874 $('.woocommerce_options_panel.wscsd_custom_start_date').css('display', 'none'); 875 $('.wscsd_variations_box').css('float', 'left'); 876 $('.wscsd_variations_box').css('width', '100%'); 877 } 878 if ($(this).val() == 'variable-subscription') { 879 $('.wscsd_variations_box').css('display', 'block'); 880 $('.woocommerce_options_panel.wscsd_custom_start_date').css('display', 'none'); 881 $('.wscsd_variations_box').css('float', 'left'); 882 $('.wscsd_variations_box').css('width', '100%'); 883 } 884 if ($(this).val() == 'subscription') { 885 $('.wscsd_variations_box').css('display', 'none'); 886 $('.woocommerce_options_panel.wscsd_custom_start_date').css('display', 'block'); 887 $('.wscsd_variations_box').css('float', 'left'); 888 $('.wscsd_variations_box').css('width', '100%'); 889 } 890 }); 891 } 892});
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.