id = 'integration-agechecker'; $this->method_title = __('AgeChecker.Net', 'woocommerce-integration-agechecker'); $this->method_description = __('E-Commerce Age Verification', 'woocommerce-integration-agechecker'); $args = array( 'number' => $number, 'orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids ); $product_categories = get_terms( 'product_cat', $args ); if ( !function_exists('get_editable_roles') ) { require_once( ABSPATH . '/wp-admin/includes/user.php' ); } $roles = []; 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->excluded_groups = $this->get_option('excluded_groups'); $this->page = $this->get_option('page'); } public function init_form_fields() { $args = array( 'number' => $number, 'orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids ); $product_categories = get_terms( 'product_cat', $args ); $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' ), 'excluded_categories' => array( 'title' => __('Exclude Categories', 'woocommerce-integration-agechecker'), 'type' => 'listbox', 'description' => __('Age verification will not be required if all of the cart products are in one these categories.', 'woocommerce-integration-agechecker'), 'default' => '', 'list' => 'categories' ), 'excluded_groups' => array( 'title' => __('Exclude Groups', 'woocommerce-integration-agechecker'), 'type' => 'listbox', 'description' => __('Age verification will be not required if the customer is in one of these groups.', 'woocommerce-integration-agechecker'), 'default' => '', 'list' => 'roles' ), 'page' => array( 'title' => __('Page', 'woocommerce-integration-agechecker'), 'type' => 'text', 'description' => __('Page to show AgeChecker.Net on.', 'woocommerce-integration-agechecker'), 'default' => 'checkout' ) ); } public function generate_listbox_html( $key, $data ) { $field = $this->plugin_id . $this->id . '_' . $key; $defaults = array( 'class' => '', 'css' => '', 'custom_attributes' => array(), 'desc_tip' => false, 'description' => '', 'title' => '', 'list' => array(), ); $args = array( 'number' => $number, 'orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids ); $product_categories = get_terms( 'product_cat', $args ); $roles = []; foreach(get_editable_roles() as $role_name => $role_info) $roles[] = $role_name; ob_start(); ?> get_tooltip_html( $data ); ?>

get_description_html( $data ); ?>
roles; $user_role = implode($roles); $excluded = true; $excludedCategories = explode(",", $this->excluded_categories); if(!(sizeof($excludedCategories) == 1 && $excludedCategories[0] == "")) { foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { $noExclude = true; foreach($excludedCategories as $c) { if(has_term($c, 'product_cat', $cart_item['data']->id)) { $noExclude = false; break; } } if($noExclude) $excluded = false; } } else $excluded = false; $excludedGroups = explode(",", $this->excluded_groups); if(!(sizeof($excludedGroups) == 1 && $excludedGroups[0] == "")) { foreach($excludedGroups as $c) { if (strpos($user_role, $c) !== false) { $excluded = true; break; } } } if ($excluded) 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_excluded_categories_field($key) { $value = $_POST["categoriesListData"]; if(!isset($value)) { ?>

Invalid excluded roles.', 'woocommerce-integration-agechecker'); ?>

Invalid excluded roles.', 'woocommerce-integration-agechecker'); ?>

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); $excluded = true; $excludedCategories = explode(",", $this->excluded_categories); if(!(sizeof($excludedCategories) == 1 && $excludedCategories[0] == "")) { foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { $noExclude = true; foreach($excludedCategories as $c) { if(has_term($c, 'product_cat', $cart_item['data']->id)) { $noExclude = false; break; } } if($noExclude) $excluded = false; } } else $excluded = false; $excludedGroups = explode(",", $this->excluded_groups); if(!(sizeof($excludedGroups) == 1 && $excludedGroups[0] == "")) { foreach($excludedGroups as $c) { if (strpos($user_role, $c) !== false) { $excluded = true; break; } } } if ($excluded) return; if (is_page($this->page)) { echo ' '; } } } endif;