!function($){function e(s,t,r,n){if(++t>Number(s.offset)+Number(s.number_requests)-1)return s.onFinished(),!0;var o,u={...{action:s.action,nonce:s.nonce,id:s.ids[t],current_index:t,number_requests:s.number_requests},...s.data};$.ajax({url:s.url,type:s.type,async:!0,cache:s.cache,dataType:s.dataType,data:u,success:function(o){var u=s.onRequestSuccess(o,t);if(o.success)r.progressbar("value",Number((t+1)/s.number_requests*100)),$(n).text(t+1);else{if(1==s.stop_on_error)return void s.onFinished();-1==s.stop_on_error&&(r.progressbar("value",Number((t+1)/s.number_requests*100)),$(n).text(t+1)),0==s.stop_on_error&&t--}u?o.success||-1===s.stop_on_error?e(s=s.updateSettings(s),t,r,n):setTimeout((function(){e(s,t,r,n)}),s.wait):s.onFinished()},error:function(o,u,c){var i=s.onRequestError(o,u,c,t);1!=s.stop_on_error?(0==s.stop_on_error&&t--,i?setTimeout((function(){e(s,t,r,n)}),s.wait):s.onFinished()):s.onFinished()}})}$.fn.synchronous_request=function(s){var t=$.extend({url:"",number_requests:0,offset:0,action:"",nonce:"",ids:"",wait:5e3,stop_on_error:0,progress_count:"#progress-number",log:"#log",cancel_button:".cancel",type:"post",cache:!1,dataType:"json",onRequestSuccess:function(e,s){if(this.maybeResetLog(),e.success)$("ul",$(this.log)).append('<li class="success">'+(s+1)+"/"+this.number_requests+": "+e.data+"</li>");else{var t=s+1+"/"+this.number_requests+": Response Error: "+e.data;switch(this.stop_on_error){case 1:break;case 0:t=t+". Waiting "+this.stop_on_error_pause/1e3+" seconds before reattempting this request.";break;case-1:t=t+". Waiting "+this.stop_on_error_pause/1e3+" seconds before attempting next request.";break}$("ul",$(this.log)).append('<li class="error">'+t+"</li>")}return 1!=this.cancelled},onRequestError:function(e,s,t,r){return $("#log ul li").length>=100&&$("#log ul").html(""),$("#log ul").append('<li class="error">'+(r+1)+"/"+ckwc_sync_past_orders.number_requests+": Request Error: "+e.status+" "+e.statusText+"</li>"),1!=this.cancelled},updateSettings:function(e){return e},onFinished:function(){this.cancelled?$("ul",$(this.log)).append('<li class="success">Process cancelled by user.</li>'):($("ul",$(this.log)).append('<li class="success">Finished.</li>'),$(t.cancel_button).attr("disabled","disabled"))},maybeResetLog:function(){$("ul li",$(this.log)).length>=100&&$("ul",$(this.log)).html("")}},s);progressbar=$(this).progressbar({value:0}),t.cancel_button&&$(t.cancel_button).on("click",(function(e){e.preventDefault(),t.cancelled=!0,$(t.cancel_button).attr("disabled","disabled")})),e(t,-1+Number(t.offset),progressbar,t.progress_count)}}(jQuery);