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_head'
), 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'
));
add_action('woocommerce_thankyou', array(
$this,
'add_script_afterpayment'
));
add_action( 'rest_api_init', array(
$this,
'establish_api'
));
$this->key = $this->get_option('key');
$this->secret = $this->get_option('secret');
$this->store_name = $this->get_option('store_name');
$this->element = $this->get_option('element');
$this->workflow_type = $this->get_option('workflow_type');
$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->enable_noscript = $this->get_option('enable_noscript');
$this->script_location = $this->get_option('script_location');
$this->category_apikeys = $this->get_option('category_apikeys');
$this->apikeys_list = $this->get_option('apikeys_list');
$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');
$this->set_customer_role = $this->get_option('set_customer_role');
// 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(
'settings_hider' => array(
'type' => 'settingshider',
'desc_tip' => false,
),
'workflow_type' => array(
'title' => 'Verification Workflow Type',
'type' => 'radio',
'description' => 'Specify where in the order process you want age verification to occur.',
'default' => 'before_payment',
'desc_tip' => false,
),
'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,
),
'secret' => array(
'title' => 'Account Secret',
'type' => 'text',
'description' => 'The Account Secret for your AgeChecker account. 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 when using the "Before Payment" workflow. 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' => 'This option only effects the "Before Payment" workflow.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' => 'This option only effects the "Before Payment" workflow.Location of script in site source',
'default' => 'head',
'desc_tip' => false,
),
'category_apikeys' => array(
'title' => 'Category Specific API Keys (Advanced)',
'type' => 'apikeys_listbox',
'default' => '{}',
'desc_tip' => false,
),
'apikeys_list' => array(
'type' => 'ordered_listbox',
'default' => 'default_api_key',
'list' => 'apikeys',
'description' => 'Move API keys with the arrow buttons to set priority of the key. Keys with a higher position on the list will take priority to be used than ones below it. (E.g. If you have a product in a cart with a category specific API key with age settings set to 21+, you would most likely want this to override another product in the cart with a category specific API key with 18+ age settings) Default API Key = API key set in the "API Key" input box at the top of the settings page',
'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',
'description' => 'This option only effects the "Before Payment" workflow. "After Payment" workflow will always add a verification status and UUID to the order fields, ignoring this setting.',
'default' => 'tag_none',
'desc_tip' => false,
),
'set_customer_role' => array(
'title' => 'Set Customer Role',
'type' => 'selectbox',
'description' => 'Add a role to a logged-in customer\'s list of user roles upon accepted verification. (Customers must be logged in to their account for the role to be added)',
'default' => 'do_not_set_role',
'list' => 'customer_role',
'desc_tip' => false,
),
'enable_noscript' => array(
'title' => 'Redirect users if Javascript is disabled',
'type' => 'radio',
'description' => 'Since AgeChecker requires Javascript to load, users will be redirected to a page letting them know to enable Javascript if it\'s disabled. Only disable this if you have another way put in place that alerts users to re-enable Javascript if disabled.',
'default' => 'enable_noscript',
'desc_tip' => false,
),
);
}
public function generate_selectbox_html($key, $data) {
$field = $this->plugin_id . $this->id . '_' . $key;
$roles = array();
foreach (get_editable_roles() as $role_name => $role_info) {
$roles[] = $role_name;
}
ob_start();
?>