What I'm trying to do is to contact WooCommerce every fifth seconds to check if a product have been edited. I can do that by asking for res[0].date_modified. Then I compare the time it was created (res[0].date_created) and last modified.
If the values are the same the product have never been modified. However if the product get modified I no longer want to compare the time the product was created and last modifed.
I now want to compare the time with the last time it got modified with "res[0].date_modified" so I can see if it gets modified another time.
This is what I have come up with:
function lookForEdit(){
WooCommerce.get('products/', function(err, WooData, res) {
res=JSON.parse(res)
var comp = res[0].date_created;
if(comp == res[0].date_modified){
console.log("the product haven't been modified")
}
else{
console.log("The product have been edited")
comp = res[0].date_modified;
}
})
}
setInterval(lookForEdit, 5000);
I understand why it doesn't work, but I don't know how to fix it.
How can I fix it?
Thanks
Also I asked this question last week and thought I got an answer that would work. The answer I got:
var comp;
function lookForEdit(){
WooCommerce.get('products/', function(err, WooData, res) {
res=JSON.parse(res)
//console.log(res[0])
if(comp == undefined){
console.log("The product haven't been editet")
comp = res[0].date_created;
}
if(comp != res[0].date_modified){
comp = res[0].date_modified;
console.log("The product have been edited")
//editAPI(res[0])
}
});
};
Then I realised that this wouldn't work when I put the function inside a for-loop to check multiple items. I can't use "comp" if checking index 0 and index 1.
Thank you again!
via WilliamG
No comments:
Post a Comment