How To Set A Check If Coupon Code Used One Time Then Do Not Allow To Use It Second Time In One Transection
This is my code html input field Scrip
Solution 1:
You can store it in an array and check if it exists before moving ahead.
Pseudo code below:
var couponArr = [];
var getcoupon = $("#couponadd").val();
if($.inArray(getcoupon, couponArr) !== -1) {
alert('Coupon already used, can\'t use again.');
} else {
couponArr.push(getcoupon);
// your code here..
}
inArray
returns the index of the element in the array, not a boolean indicating if the item exists in the array. If the element was not found, -1
will be returned.
Solution 2:
Add a global tag variable and set default to false,use a if condition wrap the code need to run,then in the run code set it to true.
such as:
// in outer spacevar hasCodeRun = false;
// in some functionif (!hasCodeRun) {
// run code here
hasCodeRun = true;
}
Post a Comment for "How To Set A Check If Coupon Code Used One Time Then Do Not Allow To Use It Second Time In One Transection"