Skip to content

Instantly share code, notes, and snippets.

@sunnysideup
Last active August 29, 2015 14:18
Show Gist options
  • Save sunnysideup/b0442bf738236e7347fa to your computer and use it in GitHub Desktop.
Save sunnysideup/b0442bf738236e7347fa to your computer and use it in GitHub Desktop.
Function to work out if a coupon is valid .... Returns false if the coupon is invalid and true if the coupon is valid.
<?php
function getIsValid() {
//we go through all the options that would make it invalid...
if(! $this->NumberOfTimesCouponCanBeUsed) {
return false;
}
if($this->getUseCount() > $this->NumberOfTimesCouponCanBeUsed) {
return false;
}
$now = strtotime("now");
$startDate = strtotime($this->StartDate);
if($now < $startDate) {
return false;
}
//include the end date itself.
$endDate = strtotime($this->EndDate)+(60*60*24);
if($now > $endDate) {
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment