Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2010
    Posts
    48
    Plugin Contributions
    1

    Default 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
    PHP 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 or !empty($_POST['dob'])) {
          if (
    substr_count($dob,'/') > || checkdate((int)substr(zen_date_raw($dob), 42), (int)substr(zen_date_raw($dob), 62), (int)substr(zen_date_raw($dob), 04)) == 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 Code:
    $minimum_age 
    to apply the age restriction that you require.
    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 Code:
    ENTRY_DATE_OF_BIRTH_UNDERAGE 
    is not strictly necessary, I just threw it in there for your reference.

    Hope this is helpful.

  2. #2
    Join Date
    Sep 2010
    Posts
    48
    Plugin Contributions
    1

    Default 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.

  3. #3
    Join Date
    Jul 2015
    Posts
    43
    Plugin Contributions
    0

    Default 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:
    Code:
      
    // 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)
    Code:
            $currentage = strtotime("now") - strtotime($dob); // Calculate current age (in seconds)
            $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
            $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);
    		  }
            // 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
    		  if(!$zone_sale_permitted == 1){
      		          $error = true;
    			  $messageStack->add('create_account', ENTRY_ZONE_SALES_PROHIBITED);
    		  }
    

 

 

Similar Threads

  1. Popup page that tests customers age
    By TheBlueDragon in forum General Questions
    Replies: 1
    Last Post: 1 Jul 2016, 05:39 PM
  2. Setting minimum age to 18 on sign up
    By TheBlueDragon in forum General Questions
    Replies: 2
    Last Post: 1 Jul 2016, 05:30 PM
  3. Minimum age for customer
    By GerryTheMole in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 5 Jul 2009, 08:47 AM
  4. Adding products as a %age of total order with minimum value
    By gaekwad in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 9 Jul 2007, 10:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg