Forums / Managing Customers and Orders / Customers minimum age

Customers minimum age

Views: 915

Results 1 to 3 of 3
1 Jul 2016, 4:21 PM
#1
ajmn avatar

ajmn

New Zenner

Join Date:
Sep 2010
Posts:
50
Plugin Contributions:
0

Customers minimum age

Hardly worth adding this to the plugins, hence offering the code here.
[I'm hoping 'minimum age' will show in the search results if searched for.]

If you want to restrict your store to a minimum age (18 shown below).
First copy the file
\includes\modules\create_account.php
to
\includes\modules[your-template]\create_account.php

then modify it with the following code

/*
  if (ACCOUNT_DOB == 'true') {
    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);
      }
    }
  }
*/
   if (ACCOUNT_DOB == 'true') {
    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);
        $messageStack->add('create_account', 'YOU MUST BE AT LEAST EIGHTEEN (18) years of age in order to purchase ANY PRODUCT from our store.');
      }                
    }
  }

Change the value of the variable ```php
$minimum_age

That's it.
Unfortunately PayPal won't verify the 'age' during checkout, their reasons are that they have to consider their customer's privacy!!!
So it's not a complete solution if you sell age restricted items ~ there are companies out there that do offer verification for a fee.

Adding a define statement ```php
ENTRY_DATE_OF_BIRTH_UNDERAGE
``` is not strictly necessary, I just threw it in there for your reference.

Hope this is helpful.
1 Jul 2016, 4:35 PM
#2
ajmn avatar

ajmn

New Zenner

Join Date:
Sep 2010
Posts:
50
Plugin Contributions:
0

Re: Customers minimum age

BTW: I've marked this for ZC v.1.5.1 but the specified code is good for ZC v.1.5.5a too.

11 Jul 2016, 10:45 PM
#3
michael_rebreathe avatar

michael_rebreathe

New Zenner

Join Date:
Jul 2015
Posts:
43
Plugin Contributions:
0

Re: Customers minimum age

I've looked around the forum to no avail, wondering if someone else has poked around heavily into our kind of specifics. We're evaluating our own coding updates, but are wondering if someone else has already integrated something fitting our needs.

The site I am supporting sells e-cigarettes. The FDA just released a not-too-small set of regulations, which are phasing in over the next couple of years. Believing that this was coming, and wanting to be one of the players who self-regulate and want to do the right thing, we already restricted sales to 18+. We chose to not have an age verification upon entry to the site, since browsing isn't the concern, but sales are. Upon account creation, we check the customer's provided birth date to verify 18+, and require an affirmation via checkbox that the buyer is 18+ before the account creation submit button is even visible on the page. The same affirmation is required for completing checkout.

Now, the playing field is getting more complex. Two states have set minimum age to 21, and one state has barred online sales entirely.

We followed a similar technique as above, but it appears that we were a bit more precise in verifying age, and the 18+ check was enabled before the site went live.
create_account.php:

  
// ACCOUNT_DOB MUST BE TRUE   Age verification (18 YOA) performed here  INSTALLED 2015-11-03
  if (ACCOUNT_DOB == 'true') {
    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);
      } else {
          $currentage = strtotime("now") - strtotime($dob); // Calculate current age (in seconds)
          $eigthteen = 18*3600*24*365.25;  // 18 years in seconds
		  if($currentage < $eigthteen) {
			  $error = true;
			  $messageStack->add('create_account', ENTRY_AGE_VERIFICATION_FAILED);
		  }
	  }
    }
  }

We're looking at changing the code in red above into something more like (obviously written as intent, rather than actual code at this point)

        $currentage = strtotime("now") - strtotime($dob); // Calculate current age (in seconds)
        [I]$minimum_age = select minimum_age from state_shipping_legal where zone = zen_db_prepare_input($_POST['state'])
        // logic here to ensure that unspecified zones are bound to 18 or 21 YOA[/I]
        $min_age = $minimum_age * (3600*24*365.25);  // minimum age in seconds
		  if($currentage < $min_age) {
  		          $error = true;
			  $messageStack->add('create_account', ENTRY_AGE_VERIFICATION_FAILED);
		  }
        [I]// Validation that state provided ($_POST['state']) is either in the zones which permit online sales or is not in the zones which prohibit online sales 
        // A bit worried that we might even have to drill down to ZIP Code granularity for both checks[/I]
		  if(!$zone_sale_permitted == 1){
  		          $error = true;
			  $messageStack->add('create_account', ENTRY_ZONE_SALES_PROHIBITED);
		  }