id = 'integration-agechecker'; $this->method_title = __('AgeChecker.Net', 'woocommerce-integration-agechecker'); $this->method_description = __('E-Commerce Age Verification', 'woocommerce-integration-agechecker'); $this->init_form_fields(); $this->init_settings(); add_action('wp_head', array( $this, 'add_script' ), 1); add_action('woocommerce_update_options_integration_integration-agechecker', array( $this, 'process_admin_options' )); add_action('woocommerce_checkout_process', array( $this, 'validate_order' )); $this->key = $this->get_option('key'); $this->store_name = $this->get_option('store_name'); $this->element = $this->get_option('element'); $this->exclude = $this->get_option('exclude'); $this->page = $this->get_option('page'); } public function init_form_fields() { $this->form_fields = array( 'key' => array( 'title' => __('API Key', 'woocommerce-integration-agechecker'), 'type' => 'text', 'description' => __('The API key for this domain. Find it in the websites tab of your AgeChecker.Net account', 'woocommerce-integration-agechecker'), 'default' => '' ), 'store_name' => array( 'title' => __('Store Name', 'woocommerce-integration-agechecker'), 'type' => 'text', 'description' => __('Display name of your store in the popup.', 'woocommerce-integration-agechecker'), 'default' => '' ), 'element' => array( 'title' => __('Element', 'woocommerce-integration-agechecker'), 'type' => 'text', 'description' => __('Element selector to attach the popup event to. (You may need to change this if you use a custom theme/template)', 'woocommerce-integration-agechecker'), 'default' => '#place_order' ), 'exclude' => array( 'title' => __('Exclude Wholesale', 'woocommerce-integration-agechecker'), 'type' => 'checkbox', 'description' => __('Exclude all roles containing "wholesale" from age verification.', 'woocommerce-integration-agechecker'), 'default' => 'no' ), 'page' => array( 'title' => __('Page', 'woocommerce-integration-agechecker'), 'type' => 'text', 'description' => __('Page to show AgeChecker.Net on.', 'woocommerce-integration-agechecker'), 'default' => 'checkout' ) ); } public function validate_order() { $current_user = wp_get_current_user(); if (!($current_user instanceof WP_User)) return; $roles = $current_user->roles; $user_role = implode($roles); if (strpos($user_role, 'wholesale') !== false && $this->exclude == "yes") return; $uuid = $_POST['agechecker_uuid']; if (!isset($uuid) || strlen($uuid) != 32) wc_add_notice(__('You must complete the age verification process! Need help? Contact help@agechecker.net'), 'error'); else { $req = json_encode(array( 'key' => $this->key, 'uuid' => $uuid ), JSON_FORCE_OBJECT); $post = wp_remote_post("https://api.agechecker.net/v1/validate", array( 'method' => 'POST', 'timeout' => 20, 'httpversion' => '1.1', 'headers' => array( 'Content-Type' => 'application/json' ), 'body' => $req )); if (is_wp_error($post)) { wc_add_notice(__('The age verification service could not verify you at this time. Need help? Contact help@agechecker.net'), 'error'); } else { $res = json_decode($post['body']); if ($res->status == "accepted") return true; else wc_add_notice(__('You have not been approved by the age verification process! Need help? Contact help@agechecker.net' . $res->status), 'error'); } } return false; } public function validate_key_field($key) { $value = $_POST[$this->plugin_id . $this->id . '_' . $key]; if (isset($value) && strlen($value) != 32) { ?>

API key invalid! Use the 32-character domain key from the website tab in your AgeChecker.Net account area.', 'woocommerce-integration-agechecker'); ?>

roles; $user_role = implode($roles); if (strpos($user_role, 'wholesale') !== false && $this->exclude == "yes") return; if (is_page($this->page)) { echo ' '; } } } endif;