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('wp_footer', array(
$this,
'add_script_footer'
), 1);
add_action('woocommerce_update_options_integration_integration-agechecker', array(
$this,
'process_admin_options'
));
add_action('woocommerce_checkout_process', array(
$this,
'validate_order'
));
add_action( 'woocommerce_new_order', array(
$this,
'add_verified_notes'
));
$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->excluded_shipping = $this->get_option('excluded_shipping');
$this->page = $this->get_option('page');
$this->enable_all = $this->get_option('enable_all');
$this->script_location = $this->get_option('script_location');
$this->client_config = wp_specialchars_decode($this->get_option('client_config'), 'double');
$this->before_script = wp_specialchars_decode($this->get_option('before_script'), 'double');
$this->tag_order = $this->get_option('tag_order');
// 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,
),
'excluded_shipping' => array(
'title' => 'Exclude Shipping Methods',
'type' => 'listbox',
'default' => '',
'list' => 'shipping_methods',
'desc_tip' => false,
),
'page' => array(
'title' => 'Page',
'type' => 'text',
'description' => 'Page to show AgeChecker.Net on.',
'default' => 'checkout',
'desc_tip' => false,
),
'enable_all' => array(
'title' => 'Enable on All Pages',
'type' => 'radio',
'description' => 'NOTE: This should only be used if "Page" box above is not working. Try setting the page name in the "Page" input box above first before using this.',
'default' => 'dont_enable_all',
'desc_tip' => false,
),
'script_location' => array(
'title' => 'Script Location',
'type' => 'radio',
'description' => 'Location of script in site source',
'default' => 'head',
'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'
),
'tag_order' => array(
'title' => 'Tag Orders',
'type' => 'radio',
'default' => 'tag_none',
'desc_tip' => false,
),
);
}
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); ?>
|
|
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;
}
$shipping_methods = array();
foreach(WC_Shipping_Zones::get_zones() as $zone_key => $zone ) {
foreach($zone['shipping_methods'] as $method_key => $method ) {
$str = "(".$zone['zone_name'].") ".$method->method_title;
$str = str_replace('"', "", $str);
$str = str_replace("'", "", $str);
$str = str_replace("`", "", $str);
$str = str_replace(",", "", $str);
$shipping_methods[] = $str;
}
}
ob_start();
?>
|
get_tooltip_html($data); ?>
|
|
is_excluded() || $this->is_shipping_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 add_verified_notes( $order_id ) {
$order = new WC_Order( $order_id );
if(isset($_POST['agechecker_uuid']) && isset($this->tag_order)) {
if($this->tag_order == "tag_notes" || $this->tag_order == "tag_both") {
$note = __("Age Verified order. \n\nAgeChecker UUID: ". $_POST['agechecker_uuid']);
$order->add_order_note( $note );
}
if($this->tag_order == "tag_fields" || $this->tag_order == "tag_both") {
$order->update_meta_data( 'Age Verified', 'AgeChecker UUID: '. $_POST['agechecker_uuid'] );
}
}
$order->save();
}
public function validate_excluded_categories_field($key) {
$value = $_POST["categoriesListData"];
if (!isset($value)) {
?>
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.'
script_location == 'footer' || $this->is_excluded() || (!is_page($this->page) && $this->enable_all == 'dont_enable_all')) {
return;
}
?>
script_location == 'head' || $this->is_excluded() || (!is_page($this->page) && $this->enable_all == 'dont_enable_all')) {
return;
}
?>
excluded_shipping);
if (!(sizeof($excluded_shipping_methods) == 1 && $excluded_shipping_methods[0] == "")) {
$all_shipping_methods = array();
foreach(WC_Shipping_Zones::get_zones() as $zone_key => $zone ) {
foreach($zone['shipping_methods'] as $method_key => $method ) {
$str = "(".$zone['zone_name'].") ".$method->method_title;
$str = str_replace('"', "", $str);
$str = str_replace("'", "", $str);
$str = str_replace("`", "", $str);
$str = str_replace(",", "", $str);
$all_shipping_methods[$method->instance_id] = $str;
}
}
$chosen_methods = WC()->session->get('chosen_shipping_methods');
if($chosen_methods) {
foreach ($chosen_methods as $shipping_method_key => $shipping_method) {
$title = $all_shipping_methods[substr(strstr($shipping_method, ":"), 1)];
foreach ($excluded_shipping_methods as $c) {
if (strpos($title, $c) !== false) {
return true;
}
}
}
}
}
return false;
}
public function is_excluded() {
$current_user = wp_get_current_user();
if (!($current_user instanceof WP_User)) {
return true;
}
$roles = $current_user->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;