Skip to content

Instantly share code, notes, and snippets.

@NiklasHogefjord
Created November 30, 2017 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NiklasHogefjord/2ce868b1efd8f8a885da1af4c85e5d0a to your computer and use it in GitHub Desktop.
Save NiklasHogefjord/2ce868b1efd8f8a885da1af4c85e5d0a to your computer and use it in GitHub Desktop.
<?php
// Validate the customers age on the validate callback from Klarna (happens right before the purchase is finalized).
// The 'Check items stock and valid shipping method during checkout' setting needs to be checked in the KCO settings for this to work.
// The store needs to have SSL/https enabled for the validate callback to work.
add_action('kco_validate_checkout', 'my_kco_validate_checkout' );
function my_kco_validate_checkout( $data ) {
// $data is the returned order data sent from Klarna
$birthday = new DateTime($data['customer']['date_of_birth']);
$now = new DateTime();
$age = $now->diff($birthday);
if( $age -> y < 18 ) {
header( 'Location: ' . wc_get_checkout_url() . '?under_age' );
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment