Remove member discounts for some items (v. 2.8+)

The Site Builder system has a members coupon area that allows a store owner to create a member code which applies a straight percent off to all items in the catalog.

To modify this functionality and keep some items from receiving this discount:

  1. Open the openinfo.php file in the /enc/ folder, and change the following code (around line 422) from:

    $memmsg .= "A $memdisc% discount for $membername will be applied.";
    $memmsg .= "

    ";

    to:

    $memmsg .= "A $memdisc% discount will be applied to selected items.";
    $memmsg .= "

    "; $disallow_member_id=array(56,89);

    where 56,89 is a list of the IDs of items that should not be discounted, separated by commas (with no spaces).

    Optional Variation #1: (updated 8/11/14 to allow multiple categories)
    If you want to automatically exclude only items in specific categories, change the above line:

    $disallow_member_id=array(56,89);

    to:

    $couponcat=array(4, 8, 12);
    $disallow_member_id=array();
    $couponitems=mysql_query("SELECT ID FROM " .SB_DB_PREFIX ."_items WHERE " .implode(' OR ', array_map(function($el){ return "Category" .implode("='$el' OR Category", range(1,15)) ."='$el'"; }, $couponcat)));
    while($coupitem=mysql_fetch_array($couponitems))
    {
    $disallow_member_id[]=$coupitem[ID];
    }

    and change the $couponcat variables 4, 8 and 12 to the ID numbers of the categories you want to exclude. (Note: you can list as many or as few categories as you'd like - just separate them with commas.)

    With this variation, any time a client assigns an item to one of the categories specified above, it will not be discounted. Items not in these categories will be discounted.

    - OR -

    Optional Variation #2: (updated 8/11/14 to allow multiple categories)
    If you want to automatically include only items in a specific category, change the above line:

    $disallow_member_id=array(56,89);

    to:

    $couponcat=array(4, 8, 12);
    $disallow_member_id=array();
    $couponitems=mysql_query( "SELECT ID FROM " .SB_DB_PREFIX ."_items WHERE " .implode(' AND ', array_map(function($el){ return "Category" .implode("<>'$el' AND Category", range(1,15)) ."<>'$el'"; }, $couponcat)));
    while($coupitem=mysql_fetch_array($couponitems))
    {
    $disallow_member_id[]=$coupitem[ID];
    }

    and change the $couponcat variables 4, 8 and 12 to the ID numbers of the categories you want to include. (Note: you can list as many or as few categories as you'd like - just separate them with commas.)

    With this variation, any time a client assigns an item to one of the categories specified above, it will be discounted. Items not in these categories will not be discounted.

  2. Open the products_variables.php files in the /enc/ folder, and change the code (around line 175) in the var_discounts function from:

    global $label_discmsg1, $label_discmsg2, $Currency;

    to:

    global $label_discmsg1, $label_discmsg2, $Currency, $disallow_member_id, $searchrow;

    and change:

    if ($membprice == "yes" AND (empty($membcode) OR $membdisc == 0))

    to:

    if(in_array($searchrow[ID], $disallow_member_id) OR ($membprice == "yes" AND (empty($membcode) OR $membdisc == 0)))
  3. In that same file, change the code (around line 507) in the var_member function from:

    global $membercode, $memdisc;

    to:

    global $membercode, $memdisc, $disallow_member_id, $searchrow;

    and change:

    if ($membercode AND $memdisc > 0 AND empty($dispoutofstock) AND empty($dispwholesale))

    to:

    if ($membercode AND $memdisc > 0 AND empty($dispoutofstock) AND empty($dispwholesale) AND !in_array($searchrow[ID], $disallow_member_id))
  4. Open the order.php file in the /go/ folder, and add the code:

    if(!in_array($productid, $disallow_member_id))

    just above the code (around line 152):

    $memdisc = (float)$memrow[Discount];
  5. In the storeadmin area, select 'Members' and add a member code and discount.

  6. After adding the member code, select it and click 'Get Code' to create the code your clients' customers will need to click to apply the coupon discount code to the store. Note that the products you specified above will not receive a discount.

See also: Member Discounts By Category Mod for a more detailed but automated modification that requires database changes.