WC_Product_Price_Based_Country

Main WC Product Price Based Country Class.

Defined (1)

The class is defined in the following location(s).

/woocommerce-product-price-based-on-countries.php  
  1. /* @class WC_Product_Price_Based_Country 
  2. * @version 1.5.6 
  3. */ 
  4. class WC_Product_Price_Based_Country { 
  5.  
  6. /** 
  7. * @var string 
  8. */ 
  9. public $version = '1.5.9'; 
  10.  
  11. /** 
  12. * @var The single instance of the class  
  13. */ 
  14. protected static $_instance = null; 
  15.  
  16. /** 
  17. * @var $regions 
  18. */ 
  19. protected $regions = null; 
  20.  
  21. /** 
  22. * @var $customer 
  23. */ 
  24. public $customer = null; 
  25.  
  26. /** 
  27. * Main WC_Product_Price_Based_Country Instance 
  28. * Ensures only one instance of WooCommerce is loaded or can be loaded. 
  29. *  
  30. * @static 
  31. * @see WCPBC() 
  32. * @return Product Price Based Country - Main instance 
  33. */ 
  34. public static function instance() { 
  35. if ( is_null( self::$_instance ) ) { 
  36. self::$_instance = new self(); 
  37. return self::$_instance; 
  38.  
  39. /** 
  40. * WC_Product_Price_Based_Country Constructor. 
  41. */ 
  42. public function __construct() {  
  43. $this->includes();  
  44. $this->init_hooks();  
  45. }  
  46.  
  47. /** 
  48. * Include required files used in admin and on the frontend. 
  49. */ 
  50. private function includes() {  
  51.  
  52. include_once( 'includes/wcpbc-functions.php' );  
  53. if ( $this->is_request( 'admin') ) { 
  54. include_once( 'includes/class-wcpbc-install.php' ); 
  55. include_once( 'includes/admin/class-wcpbc-admin.php' );  
  56.  
  57. } elseif ( $this->is_request( 'frontend') ) { 
  58. include_once( 'includes/class-wcpbc-frontend.php' ); 
  59. include_once( 'includes/class-wcpbc-customer.php' );  
  60. include_once( 'includes/class-wcpbc-product-price.php' ); 
  61. include_once( 'includes/class-wcpbc-country-selector.php' );  
  62.  
  63. /** 
  64. * Hook actions 
  65. */ 
  66. private function init_hooks() { 
  67. register_activation_hook( __FILE__, array( 'WCPBC_Install', 'install' ) ); 
  68.  
  69. add_action( 'widgets_init', array($this, 'register_widgets') );  
  70.  
  71. if ( ! $this->is_request( 'admin') && $this->is_request( 'frontend') ) {  
  72.  
  73. add_action( 'woocommerce_init', array( $this , 'frontend_init'), 50 );  
  74.  
  75. /** 
  76. * What type of request is this? 
  77. * string $type frontend or admin 
  78. * @return bool 
  79. */ 
  80. private function is_request( $type ) { 
  81.  
  82. $is_ajax = defined('DOING_AJAX') && DOING_AJAX; 
  83.  
  84. switch ( $type ) { 
  85. case 'admin' :  
  86. $ajax_allow_actions = array( 'woocommerce_add_variation', 'woocommerce_load_variations', 'woocommerce_save_variations' ); 
  87. return ( is_admin() && !$is_ajax ) || ( is_admin() && $is_ajax && isset( $_POST['action'] ) && in_array( $_POST['action'], $ajax_allow_actions ) ); 
  88.  
  89. case 'frontend' : 
  90. return ! $this->is_request('bot') && ( ! is_admin() || ( is_admin() && $is_ajax ) ) && ! defined( 'DOING_CRON' );  
  91.  
  92. case 'bot': 
  93. $user_agent = strtolower ( $_SERVER['HTTP_USER_AGENT'] ); 
  94. return preg_match ( "/googlebot|adsbot|yahooseeker|yahoobot|msnbot|watchmouse|pingdom\.com|feedfetcher-google/", $user_agent ); 
  95.  
  96. /** 
  97. * Register Widgets 
  98. * @since 1.5.0 
  99. */ 
  100. public function register_widgets() {  
  101. include_once( 'includes/class-wcpbc-widget-country-selector.php' );  
  102. register_widget( 'WCPBC_Widget_Country_Selector' ); 
  103.  
  104. /** 
  105. * Init front-end variables 
  106. */ 
  107. public function frontend_init() {  
  108. $this->customer = new WCPBC_Customer();  
  109. do_action('wc_price_based_country_frontend_init'); 
  110.  
  111. /** 
  112. * Get regions 
  113. * @return array 
  114. */ 
  115. public function get_regions() { 
  116. if ( is_null( $this->regions ) ) { 
  117. $this->regions = get_option( 'wc_price_based_country_regions', array() );  
  118. }  
  119. return $this->regions; 
  120.  
  121. /** 
  122. * Get the plugin url. 
  123. * @return string 
  124. */ 
  125. public function plugin_url() {  
  126. return plugin_dir_url( __FILE__ ); 
  127.  
  128. /** 
  129. * Get the plugin path. 
  130. * @return string 
  131. */ 
  132.  
  133. public function plugin_path() { 
  134. return plugin_dir_path( __FILE__ );