I tried to enter this in tips and tricks, but I guess it would have to be moved if deemed helpful. A while back I had looked for something to do an external check on the promo code database in order to integrate it with an external (API) based form, and did not really have any luck. So, this code I am posting does work - but do keep in mind the comments, code structure, and everything does work, but is not optimized fully - the actual version we converted to an API function and integrated with XAJAX and JQuery on the front end. Anyway, I figured that if I needed to find something like this and it was not available, that I would provide my previous script since I am sure someone else has looked for it before. I would release the XAJAX API version, but I am unable to publicly release it (not because it was very difficult, but because my client agreement does not allow me to release any code that is actually in use). There are more efficient ways of doing the checks which we implemented in the API version, but again I just cannot release that code at this time, and I am sure the WHMCS developers have already created this possibility for future API versions - but for now, it does work. Anyway, here you go - again, unrefined but it is a way to check promo code validity (expiration, product type, and billing cycle only) and return its values in an array. I do not have much time to assist in anything, but if you have a small question I would probably be happy to HELP (not give beginner PHP lessons). I am posting this to help others LEARN or at least take some initiative to learn - I did take about an hour or so to comment the code before this post, so it should be pretty self explanatory. I have also attached a text file, if you want to test this on your server (has to reside on your whmcs server), just rename to *.php and be sure to edit the form drop down product id's, and also the db values and it should be good to go. [PHP] = $todaysdate OR $expirationdate == "0000-00-00") { ## 2. now check if valid for the chosen products and term // generate arrays for the billing cycles and for the valid products $cyclesarray = explode(',', $cycles); // outputs the valid cycles which are separated by commas into an array for processing $productsarray = explode(',', $appliesto); // outputs the products which are separated by commas into an array for processing // just add these to the response right now since they will not change from this point on and no point in adding them in the if statements $pr['validproducts'] = $productsarray; // products that this code is valid for $pr['validcycles'] = $cyclesarray; // provide the cycles that this code is valid for so that the user could try changing their plan to one it would work on if (in_array($bc, $cyclesarray) OR $cycles == "") { // ok, promocode is valid for the billing cycle selected ## 3. continue to check if valid for specified product if (in_array($plannum, $productsarray)) { // ok, code is valid for billing cycle and product selected ## 4. Check if code has passed its maximum number of uses // do math to subtract used number from maximum number to see if this code can be used again $usesleft = $maxuses - $uses; if ($usesleft > 0) { ## GREAT! Product code has some free uses left, is not expired, is valid for the selected billing cycle, and is valid for the selected product ## congrats, our code is valid and we can notify the user and apply their discount // this is the only VALID response we give to users, since a passcode can only be accepted or rejected and there is no inbetween $pr['valid'] = 1; // promo is valid $pr['errorcode'] = 0; // there is no error code $pr['discounttype'] = $type; // percent or fixed? $pr['discountvalue'] = $value; // the value of the promo code (use the discounttype response to create logic for % or $ calculation) $pr['expirationdate'] = $expirationdate; $pr['maxuses'] = $maxuses; // maximum number of uses $pr['usesleft'] = $usesleft; // number of uses left before code is no longer valid $pr['uses'] = $uses; // number of times code was used return $pr; } else ## CHECK 4 FAILED because the maximum code uses has passed { $pr['valid'] = 0; $pr['errorcode'] = 4; $pr['reason'] = 'Maximum promo code use has been reached'; $pr['expirationdate'] = $expirationdate; $pr['maxuses'] = $maxuses; $pr['usesleft'] = $usesleft; $pr['uses'] = $uses; return $pr; } } else ## CHECK 3 FAILED because the code is not valid for the selected product that the user has chosen { $pr['valid'] = 0; $pr['errorcode'] = 3; $pr['reason'] = 'Not valid for selected product type'; $pr['expirationdate'] = $expirationdate; return $pr; } } else ## CHECK 2 FAILED because the code is not valid for the billing cycle the user has chosen { $pr['valid'] = 0; $pr['errorcode'] = 2; $pr['reason'] = 'Not valid for selected billing cycle'; $pr['expirationdate'] = $expirationdate; return $pr; } } elseif ($expires <= $todaysdate) ## CHECK 1 FAILED because promo code has expired, or your servers date and time is screwed up { $pr['valid'] = 0; $pr['errorcode'] = 1; $pr['reason'] = 'Expired'; $pr['expirationdate'] = $expirationdate; return $pr; } else ## CHECK 1 FAILED because something went wrong when checking if code was expired, could be that the date is not being calculated correctly { $pr['valid'] = 0; $pr['errorcode'] = 98; $pr['reason'] = 'Unknown Error While Determining Expiration'; $pr['expirationdate'] = $expirationdate; return $pr; } } else ## CHECK 0 FAILED because something went wrong when checking for the promo code, but we don't know what so we just respond with invalid { $pr['valid'] = 0; $pr['errorcode'] = 99; $pr['reason'] = 'Unknown error when checking for promo code validity, please try again.'; return $pr; } } ?> WHMCS Promo Code Test

Response Output Array
";
    var_dump($response);
    print "
"; // Print an individual value for the array, for example if the code is valid or not, show something print "

User Friendly Response Example:

"; if($response["valid"]!=1){ // show error if code is not valid echo '

Sorry! Promocode' . $response["promocode"] . ' is not a valid promo code for the following reason: ' . $response["reason"] . '

'; } else { // show if code is valid - these variables don't have to be printed, but could be used in your script or could update your order form using javascript (which is what we did with XAJAX) echo '

Congrats! Promocode ' . $response["promocode"] . ' was accepted! You are now saving ' . $response["discounttype"] . $response["value"] . ' on your order!

'; } }else{ echo '

Sorry! You have to at least enter a promo code to check!

'; } } ####### END EXAMPLE ######## ?> [/PHP]