PHP Add to Cart Help

I have an ecommerce site that I did not build but I am editing. I have 3 categories that I do not want the “add to cart” button and the “qty” button to show up. I want it to display a message instead. I have been successful with doing this with 1 of the categories but can not come up with the correct combination of code to get it to work for all 3 categories. Any help would be appreciated.

[php]// Add to cart or login
if (hasAccessByLevel(6, ‘LTE’, $userName) && $cat != “jewelry”){

if (isset($error)) {
echo ("<div class=“error”>

$error


“);
}
echo(”<form name=“addtocart” method=“post” action=“plugins/addtocart.php” id=“addtocart”><input name=“sku” type=“hidden” value="$product[sku]"/>");
if (isset($cat)){
echo("<input name=“category” type=“hidden” value="$cat"/>");
}
if (!empty($eCatalogReturnURL)){
echo("<input name=“eCatalogReturnURL” type=“hidden” value="$eCatalogReturnURL"/>");
}
echo("<td style=“padding-top:6px;”>Qty:
<input name=“qty” type=“text” id=“qty” value="$product[minimum]" maxlength=“4” style=“width:40px; margin-left:5px; margin-bottom:10px;”/>

<input type=“submit” name=“addtocart” value=“Add to Cart” class=“btn”/>");
if (!empty($eCatalogReturnURL)){
echo(“

If add to cart is successful, you will be redirected back to the flip-page catalog.

”);
}
} else {

if ($cat == “jewelry”) {
echo (“Please contact customer service to purchase Boutique items.”);
}

elseif ($displayType == "full") {
		  echo("<h3>You must log in to purchase this item:</h3><a class=\"btn\" href=\"register.php\" style=\"margin-right:7px;\" >Register</a><a class=\"btn\" href=\"login.php\">Log in</a>"); 
	   } elseif ($displayType == "basic") {
		  echo("<h3>You must log in to purchase this item:</h3><a class=\"btn\" href=\"javascript:self.close();\" onclick=\"window.opener.location.href='register.php';\" style=\"margin-right:7px;\" >Register</a><a class=\"btn\" href=\"javascript:self.close();\" onclick=\"window.opener.location.href='login.php';\">Log in</a>"); 
	   }

}

echo ("");[/php]

Without some more of your code or more explanation it’s hard to say for sure where to put the needed code but I will attempt based on what you have shown.
Above this line
[php]if (hasAccessByLevel(6, ‘LTE’, $userName) && $cat != “jewelry”){[/php]
Make an array of the categories that you want to limit. Then change the if block also like I show below.
[php]
$restricted = array(‘jewelry’, ‘another’, ‘another’);
if (hasAccessByLevel(6, ‘LTE’, $userName) && !in_array($cat, $restricted)){
[/php]

That was it! Thanks worked perfectly. I had the array but did not have the !in_array.

Sponsor our Newsletter | Privacy Policy | Terms of Service