public static function instance()
 {
     if (!self::$instance) {
         self::$instance = new WC_Catalog_Restrictions_Query();
     }
     return self::$instance;
 }
 public function __construct()
 {
     define('WOOCOMMERCE_CATALOG_RESTRICTIONS_VERSION', $this->version);
     $this->template_url = apply_filters('woocommerce_catalog_restrictions_template_url', 'woocommerce-catalog-visibility-options/');
     require 'woocommerce-catalog-restrictions-functions.php';
     require 'shortcodes/class-wc-catalog-restrictions-location-picker-shortcode.php';
     require 'widgets/class-wc-catalog-restrictions-location-picker-widget.php';
     WC_Catalog_Restrictions_Location_Picker_ShortCode::instance();
     WC_Catalog_Restrictions_Location_Picker_Widget::register();
     if (is_admin()) {
         require 'classes/class-wc-catalog-restrictions-product-admin.php';
         require 'classes/class-wc-catalog-restrictions-category-admin.php';
         WC_Catalog_Restrictions_Product_Admin::instance();
         WC_Catalog_Restrictions_Category_Admin::instance();
         if ($this->get_setting('_wc_restrictions_locations_enabled', 'no') == 'yes') {
             require 'classes/class-wc-catalog-restrictions-user-admin.php';
             WC_Catalog_Restrictions_User_Admin::instance();
         }
     } else {
         add_action('woocommerce_init', array($this, 'on_init'));
         require 'classes/class-wc-catalog-restrictions-query.php';
         require 'classes/class-wc-catalog-restrictions-filters.php';
         WC_Catalog_Restrictions_Query::instance();
         WC_Catalog_Restrictions_Filters::instance();
         //load after woocommerce
         if ($this->get_setting('_wc_restrictions_locations_enabled', 'no') == 'yes') {
             add_filter('template_redirect', array(&$this, 'template_redirect'), 999);
         }
     }
     if (is_admin() && !defined('DOING_AJAX')) {
         require 'woocommerce-catalog-restrictions-installer.php';
         $this->install();
         add_action('admin_init', array($this, 'on_admin_init'));
     }
     //Setup Hooks to clear transients when a post is saved, a category is saved, a user changes their location, a user is updated, a user logs on / out.
     add_action('save_post', array(&$this, 'clear_transients'));
     add_action('created_term', array(&$this, 'clear_transients'));
     add_action('edit_term', array(&$this, 'clear_transients'));
     add_action('edit_user_profile_update', array(&$this, 'clear_transients'));
     add_action('user_register', array(&$this, 'clear_session_transients'));
     add_action('wp_login', array(&$this, 'clear_session_transients'));
     add_action('wp_logout', array(&$this, 'clear_session_transients'));
     add_action('wc_restrictions_location_updated', array(&$this, 'clear_session_transients'));
     add_action('wc_restrictions_location_updated', array($this, 'maybe_clear_cart'));
 }