tools.js
2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
jQuery( document ).ready( function( $ ) {
var LD_WC_Tools = LD_WC_Tools || {};
LD_WC_Tools.init = function() {
LD_WC_Tools.start_retroactive_access();
};
LD_WC_Tools.start_retroactive_access = function() {
if ( LD_WC_Tools_Params.wc_version < '5.6' ) {
$( 'a.button.learndash_retroactive_access' ).on( 'click', function(event) {
event.preventDefault();
/* Act on the event */
$( this ).parent( 'td' ).append( '<p class="description" id="ld-wc-retroactive-status"></p>');
$( '#ld-wc-retroactive-status' ).text( LD_WC_Tools_Params.text.keep_page_open + ' ' + LD_WC_Tools_Params.text.status + ': 0%' );
$( 'a.button.learndash_retroactive_access' ).text( '' ).addClass( 'ld-wc-spinner' );
LD_WC_Tools.process_retroactive_access();
});
} else if ( LD_WC_Tools_Params.wc_version >= '5.6' ) {
$( '.button[form="form_learndash_retroactive_access"]' ).on( 'click', function(event) {
event.preventDefault();
/* Act on the event */
$( this ).blur();
$( this ).parent( 'td' ).append( '<p class="description" id="ld-wc-retroactive-status"></p>');
$( '#ld-wc-retroactive-status' ).text( LD_WC_Tools_Params.text.keep_page_open + ' ' + LD_WC_Tools_Params.text.status + ': 0%' );
$( this ).val( '' ).addClass( 'ld-wc-spinner' );
LD_WC_Tools.process_retroactive_access();
});
}
};
LD_WC_Tools.process_retroactive_access = function( step = 1, last_order_step = 0, subscription_step = 0 ) {
$.ajax({
url: ajaxurl,
type: 'POST',
dataType: 'json',
data: {
action: 'ld_wc_retroactive_access',
nonce: LD_WC_Tools_Params.nonce.retroactive_access,
step: step,
last_order_step: last_order_step,
subscription_step: subscription_step,
},
}).done( function( data ) {
console.log( data );
if ( typeof( data ) != 'undefined' ) {
if ( data.step !== 'complete' ) {
$( '#ld-wc-retroactive-status' ).text( LD_WC_Tools_Params.text.keep_page_open + ' ' + LD_WC_Tools_Params.text.status + ': ' + data.percentage + '%' );
LD_WC_Tools.process_retroactive_access( data.step, data.last_order_step, data.subscription_step );
} else {
// done
if ( LD_WC_Tools_Params.wc_version < '5.6' ) {
$( 'a.button.learndash_retroactive_access' ).text( LD_WC_Tools_Params.text.retroactive_button ).removeClass( 'ld-wc-spinner' );
} else if ( LD_WC_Tools_Params.wc_version >= '5.6' ) {
$( '.button[form="form_learndash_retroactive_access"]' ).val( LD_WC_Tools_Params.text.retroactive_button ).removeClass( 'ld-wc-spinner' );
}
$( '#ld-wc-retroactive-status' ).text( LD_WC_Tools_Params.text.status + ': ' + LD_WC_Tools_Params.text.complete );
}
}
});
};
LD_WC_Tools.init();
});