-
-
Save NiklasHogefjord/2ce868b1efd8f8a885da1af4c85e5d0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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