jQuery(document).ready(function(){
jQuery(document.body).on("updated_checkout", async function (){
console.clear();
await getAuspostRatesRequestLogs();
});
jQuery(document.body).on("updated_cart_totals", async function (){
console.clear();
await getAuspostRatesRequestLogs();
});
});
async function getAuspostRatesRequestLogs(){
const response=await jQuery.ajax({
type: "get",
url: auspost_cart_checkout.ajax_url,
data: {
action: "auspost_get_rates_request_logs",
_ajax_nonce: auspost_cart_checkout.nonce,
},
dataType: "json",
});
if(response?.success&&response?.data){
const responseData=response?.data;
if(responseData?.auspost_rates_logs){
console.log(responseData?.auspost_rates_logs
?.replaceAll("%colored_text_start%", "%c")
?.replaceAll("%colored_text_end%", "%c"),
responseData?.auspost_rates_logs?.includes("%colored_text_start%")
? "color: red"
: "",
responseData?.auspost_rates_logs?.includes("%colored_text_end%")
? "color: initial"
: ""
);
}}
}
jQuery(document).ready(function (){
const originalFetch=window.fetch;
window.fetch=new Proxy(originalFetch, {
apply: async function (target, thisArg, argumentsList){
const url=argumentsList[0];
const options=argumentsList[1];
if(url.includes("/wp-json/wc/store/") &&
options &&
options.method==="POST"
){
const response=await target.apply(thisArg, argumentsList);
if(window?.wp?.data?.select("wc/store/cart")?.getCartData()){
getAuspostRatesRequestLogs();
}
return response;
}else{
return target.apply(thisArg, argumentsList);
}},
});
});