function on_add_tab() { $page = WC_Catalog_Visibility_Compatibility::is_wc_version_gte_2_2() ? 'wc-settings' : 'woocommerce'; foreach ($this->settings_tabs as $name => $label) { $class = 'nav-tab'; if ($this->current_tab == $name) { $class .= ' nav-tab-active'; } echo '<a href="' . admin_url('admin.php?page=' . $page . '&tab=' . $name) . '" class="' . $class . '">' . $label . '</a>'; } }
function install_woocommerce_catalog_restrictions() { global $woocommerce, $wc_catalog_restrictions, $wpdb; if (!WC_Catalog_Visibility_Compatibility::is_wc_version_gte_2_1()) { include_once $woocommerce->plugin_path() . '/admin/woocommerce-admin-install.php'; } //Clean up old rules. $wc_term_meta_table = $wpdb->prefix . 'woocommerce_termmeta'; $wpdb->query("DELETE FROM {$wc_term_meta_table} WHERE (meta_key = '_wc_restrictions' OR meta_key = '_wc_restrictions_allowed') AND (meta_value = '');"); $wpdb->query("DELETE FROM {$wc_term_meta_table} WHERE (meta_key = '_wc_restrictions_location' OR meta_key = '_wc_restrictions_locations') AND (meta_value = '');"); //Clean up the transients $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_twccr%'"); $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_twccr%'"); if (!get_option('woocommerce_choose_location_page_id')) { if (!WC_Catalog_Visibility_Compatibility::is_wc_version_gte_2_1()) { wc_create_page(esc_sql(_x('choose-location', 'page_slug', 'wc_catalog_restrictions')), 'woocommerce_choose_location_page_id', __('Your Location', 'wc_catalog_restrictions'), '[location_picker /]'); } else { woocommerce_create_page(esc_sql(_x('choose-location', 'page_slug', 'wc_catalog_restrictions')), 'woocommerce_choose_location_page_id', __('Your Location', 'wc_catalog_restrictions'), '[location_picker /]'); } } update_option("woocommerce_catalog_restrictions_db_version", $wc_catalog_restrictions->version); }
public function get_location_for_current_user() { global $woocommerce; $location = false; if (is_user_logged_in()) { $location = get_user_meta(get_current_user_id(), '_wc_location', true); } if (!empty($location)) { return $location; } $session =& WC_Catalog_Visibility_Compatibility::WC()->session; $location = isset($session) && isset($session->wc_location) ? $session->wc_location : ''; if (empty($location) && function_exists('wc_get_customer_default_location') && $this->get_setting('_wc_restrictions_locations_use_geo', 'yes') == 'yes') { $l = wc_get_customer_default_location(); if (isset($l['country'])) { $location = $l['country']; } } return apply_filters('woocommerce_catalog_restrictions_get_user_location', $location); }
public function get_cached_exclusions($type, $session_id = false) { global $woocommerce; if ($session_id === false) { $session_id = WC_Catalog_Visibility_Compatibility::WC()->session->get_customer_id(); } return get_transient('twccr_' . $session_id . '_' . $type); }