It might be better to write it this way for that function:
Code:
function credit_selection() {
global $discount_coupon;
// note the placement of the redeem code can be moved within the array on the instructions or the title
// bof: stop discount coupon for anyone in a customer group
global $db;
$allow_discount = true;
$chk_group = $db->Execute("select customers_group_pricing from " . TABLE_CUSTOMERS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
if ($chk_group->fields['customers_group_pricing'] > 0) {
$allow_discount = false;
}
if ($allow_discount) {
// eof: stop discount coupon for anyone with an order
$selection = array('id' => $this->code,
'module' => $this->title,
'redeem_instructions' => MODULE_ORDER_TOTAL_COUPON_REDEEM_INSTRUCTIONS . ($discount_coupon->fields['coupon_code'] != '' ? MODULE_ORDER_TOTAL_COUPON_REMOVE_INSTRUCTIONS : ''),
'fields' => array(array('title' => ($discount_coupon->fields['coupon_code'] != '' ? MODULE_ORDER_TOTAL_COUPON_TEXT_CURRENT_CODE . '<a href="javascript:couponpopupWindow(\'' . zen_href_link(FILENAME_POPUP_COUPON_HELP, 'cID=' . $_SESSION['cc_id']) . '\')">' . $discount_coupon->fields['coupon_code'] . '</a><br />' : '') . MODULE_ORDER_TOTAL_COUPON_TEXT_ENTER_CODE,
'field' => zen_draw_input_field('dc_redeem_code', '', 'id="disc-' . $this->code . '" onkeyup="submitFunction(0,0)"'),
'tag' => 'disc-'.$this->code
)));
}
return $selection;
}
Then for blocking the coupon abc123 from customers with previous orders go to the function collect_posts and add the test for that coupon ...
Code:
// bof: coupon abc123 for first time customers only
if ($discount_coupon->fields['coupon_code'] == 'abc123') {
global $db;
$chk_group = $db->Execute("select orders_id from " . TABLE_ORDERS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
if ($chk_group->RecordCount() > 0) {
$foundvalid = false;
}
}
// eof: coupon abc123 for first time customers only
if (!$foundvalid) {
$this->clear_posts();
}
First, set that the coupon is valid, then do the two tests and only worry about setting the coupon as invalid based on the IF conditions ...
If neither are valid, the the coupon is valid, if either the group is valid or the coupon is abc123 and there is a previous order, the the coupon would not processes ...
See if that works better ...
The reason for the change is, the first condition on the Customer Groups is to stop ALL coupons from happening for a customer in a group ... the second one is to only stop a specific coupon from a customer with a previous order and not stop the customer for using other coupons that might be valid ...
Bookmarks