One of the products I sell contains alcohol (whiskey cake). I want to "verify" the customers age before they purchase this item. I do not want to ask every customer for their age so I disabled the DOB feature in admin. Of course there is no fool proof method, but I would at least like a record of their birth date.
I added the following code to tpl_product_info_display.php to show the DOB input field. It only shows on products_id 202 (whiskey cake).
<!--bof Age Verification -->
<?php
if ($_GET['products_id'] == "202") {
?>
<fieldset>
<legend ><?php echo TABLE_HEADING_DATE_OF_BIRTH; ?></legend>
<label class="inputLabel" for="dob"><?php echo ENTRY_DATE_OF_BIRTH; ?></label>
<label class="inputLabel"><?php echo zen_draw_input_field('dob','', 'id="dob"') . (zen_not_null(ENTRY_DATE_OF_BIRTH_TEXT) ? '<br/><span class="alert">' . ENTRY_DATE_OF_BIRTH_TEXT . '</span>': ''); ?></label>
<br class="clearBoth" />
<label class="notice"><?php echo TEXT_AGE_VERIFY; ?></label>
<br class="clearBoth" />
</fieldset>
<?php
}
?>
<!--eof Age Verification-->
The next step is to check the DOB and verify that it is (1) a real date and (2) the date entered meets the criteria of 21 years of age. I found this bit of code in the tutorials "How can I limit the age of my customers to people over 18?" and modified it below.
if (ENTRY_DOB_MIN_LENGTH > 0 or !empty($_POST['dob'])) {
if (substr_count($dob,'/') > 2 || checkdate((int)substr(zen_date_raw($dob), 4, 2), (int)substr(zen_date_raw($dob), 6, 2), (int)substr(zen_date_raw($dob), 0, 4)) == false) {
$error = true;
$messageStack->add('create_account', ENTRY_DATE_OF_BIRTH_ERROR);
}
$minimum_age = 18;
$acceptable_dob = (date('Y') - $minimum_age) . date('md');
if (zen_date_raw($dob) > $acceptable_dob) {
$error = true;
$messageStack->add('create_account', ENTRY_DATE_OF_BIRTH_UNDERAGE);
}
}
I don't know if the above code will work or where to insert this code. I would like the customer to stay on the whiskey cake page, receive an error message if they are under 21 and not be able to add the cake to the shopping cart.
I have a second problem if the item is added to the shopping cart and the customer wants to return to the whiskey cake page using the product ink, a bunch on characters are added to the products_id and the above "if" statement fails. How can I only check the first 3 characters of the products_id?
Thx Sweet
Bookmarks