Code below is part of cart66 WordPress plugin’s php file. When I list options of my items for example,
T-shirt
Quantity: 1
Option: Red, Yellow, Blue
First option is always what I put first in the list. Therefore, when my customers don’t pay an attention and add to cart without looking at the list they order red. I added “Please choose a pattern” option at the top but they still add that to cart and checkout. Is there a way of adding an option and making it give an error in case that option is selected ?
private function _buildOptionList($optNumber) {
$select = '';
$optionName = "options_$optNumber";
if(strlen($this->$optionName) > 1) {
$select = "\n<select name=\"options_$optNumber\" id=\"options_$optNumber\" class=\"cart66Options options_$optNumber\">";
$opts = split(',', $this->$optionName);
foreach($opts as $opt) {
$opt = str_replace('+$', '+ $', $opt);
$opt = trim($opt);
$optDisplay = str_replace('$', CART66_CURRENCY_SYMBOL, $opt);
$select .= "\n\t<option value=\"" . htmlentities($opt) . "\">$optDisplay</option>";
}
$select .= "\n</select>";
}
return $select;
}
You could use jQuery and Javascript to show an alert box.
Make sure to include a recent copy of jQuery in your page, and change the id=”” value of the selectbox to options (without any PHP variable).
Also, don’t forget to still check in PHP if the user submitted a valid color. Do this because if the user has Javascript disabled, he will still be able to choose the ‘please choose a pattern’ item.