id = 'integration-agechecker'; $this->method_title = 'AgeChecker.Net'; $product_categories = get_terms('product_cat'); if (!function_exists('get_editable_roles')) { require_once(ABSPATH . '/wp-admin/includes/user.php'); } $roles = array(); foreach (get_editable_roles() as $role_name => $role_info) { $roles[] = $role_name; } $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->excluded_categories = $this->get_option('excluded_categories'); $this->categories_mode = $this->get_option('categories_mode'); $this->excluded_groups = $this->get_option('excluded_groups'); $this->groups_mode = $this->get_option('groups_mode'); $this->page = $this->get_option('page'); $this->client_config = wp_specialchars_decode($this->get_option('client_config'), 'double'); $this->before_script = wp_specialchars_decode($this->get_option('before_script'), 'double'); // Set settings to version without entity codes. $this->settings['client_config'] = $this->client_config; $this->settings['before_script'] = $this->before_script; } public function init_form_fields() { $this->form_fields = array( 'key' => array( 'title' => 'API Key', 'type' => 'text', 'description' => 'The API key for this domain. Find it in the websites tab of your AgeChecker.Net account.', 'default' => '', 'desc_tip' => false, ), 'store_name' => array( 'title' => 'Store Name', 'type' => 'text', 'description' => 'Display name of your store in the popup.', 'default' => get_bloginfo('name'), 'desc_tip' => false, ), 'element' => array( 'title' => 'Element', 'type' => 'text', 'description' => 'Element selector to attach the popup event to. You may need to change this if you use a custom theme/template. Please contact us if the popup is not showing when the element is clicked. The default element is the final checkout button.', 'default' => '#place_order', 'desc_tip' => false, ), 'excluded_categories' => array( 'title' => 'Exclude/Include Categories', 'type' => 'listbox', 'default' => '', 'list' => 'categories', 'desc_tip' => false, ), 'categories_mode' => array( 'type' => 'radio', 'default' => 'exclude', 'list' => 'categories', 'desc_tip' => false, ), 'excluded_groups' => array( 'title' => 'Exclude/Include Groups', 'type' => 'listbox', 'default' => '', 'list' => 'roles', 'desc_tip' => false, ), 'groups_mode' => array( 'type' => 'radio', 'default' => 'exclude', 'list' => 'roles', 'desc_tip' => false, ), 'page' => array( 'title' => 'Page', 'type' => 'text', 'description' => 'Page to show AgeChecker.Net on.', 'default' => 'checkout', 'desc_tip' => false, ), 'client_config' => array( 'title' => 'Additional Config (Advanced)', 'type' => 'textarea', 'description' => 'Other additional configuration options from our client API.', 'desc_tip' => false, 'css' => 'width: 400px' ), 'before_script' => array( 'title' => 'Before Load Script (Advanced)', 'type' => 'textarea', 'description' => 'Custom code to run before the script is loaded. Use "return" to prevent loading.', 'desc_tip' => false, 'css' => 'width: 400px' ) ); } public function generate_radio_html($key, $data) { $field = $this->plugin_id . $this->id . '_' . $key; $excluded = true; if($this->get_option($key) == 'include') $excluded = false; ob_start(); ?> get_tooltip_html($data); ?>

> Exclude listed from age verification
> Include listed for age verification

get_description_html($data); ?>
plugin_id . $this->id . '_' . $key; $product_categories = get_terms('product_cat'); $roles = array(); foreach (get_editable_roles() as $role_name => $role_info) { $roles[] = $role_name; } ob_start(); ?> get_tooltip_html($data); ?>

get_description_html($data); ?>
is_excluded()) { return true; } $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 or try using another device or browser. (Error WP201)', '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 WP203)', '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. (Error WP205)' . $res->status, 'error'); } } } return false; } public function validate_excluded_categories_field($key) { $value = $_POST["categoriesListData"]; if (!isset($value)) { ?>

Invalid excluded roles.

Invalid excluded roles.

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

is_excluded() || !is_page($this->page)) { return; } ?> roles; $user_role = implode($roles); $excluded = true; $categories_excluded = strpos($this->categories_mode, "exclude"); $categories = explode(",", $this->excluded_categories); if (!(sizeof($categories) == 1 && $categories[0] == "")) { if($categories_excluded !== false) { foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { $noExclude = true; foreach ($categories as $c) { if (has_term($c, 'product_cat', $cart_item['data']->id)) { $noExclude = false; break; } } if ($noExclude) { $excluded = false; } } } else { foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { $noExclude = false; foreach ($categories as $c) { if (has_term($c, 'product_cat', $cart_item['data']->id)) { $noExclude = true; break; } } if ($noExclude) { $excluded = false; } } } } else { $excluded = false; } $groups_excluded = strpos($this->groups_mode, "exclude"); $groups = explode(",", $this->excluded_groups); if (!(sizeof($groups) == 1 && $groups[0] == "")) { if($groups_excluded !== false) { foreach ($groups as $c) { if (strpos($user_role, $c) !== false) { $excluded = true; break; } } } else if(!$excluded) { $excluded = true; foreach ($groups as $c) { if (strpos($user_role, $c) !== false) { $excluded = false; break; } } } } return $excluded; } } endif;