In this tutorial, we show a code to restrict the user the age of 18 as the minimum age.

To do this, the validation class (class / Validation.php) that birthday check is used. But we use the override to avoid modifying core files of PrestaShop.

First, create a new php file called Validation.php, and put this content:

class Validate extends ValidateCore {
public static function isBirthDate($date)
{
if (empty($date) || $date == '0000-00-00')
return false;
if (preg_match('/^([0-9]{4})-((?:0?[1-9])|(?:1[0-2]))-((?:0?[1-9])|(?:[1-2][0-9])|(?:3[01]))([0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $date, $birth_date))
{
if ((floor((time() - strtotime($date))/31556926))<18)
return false;
if ($birth_date[1] > date('Y') && $birth_date[2] > date('m') && $birth_date[3] > date('d'))
return false;
return true;
}
return false;
}
}

and copy this file to overrides/classes directory of PrestaShop. After that, delete the file cache/class_index.php to load the new override and thats all

Product added to wishlist
Product added to compare.

We use a selection of our own and third-party cookies on the pages of this website: Essential cookies, which are required in order to use the website; functional cookies, which provide better easy of use when using the website; performance cookies, which we use to generate aggregated data on website use and statistics; and marketing cookies, which are used to display relevant content and advertising. If you choose "ACCEPT ALL", you consent to the use of all cookies. You can accept and reject individual cookie types and revoke your consent for the future at any time under "Settings".