WC_Location_Report

# WooCommerce Location Report Main Plugin Class.

Defined (1)

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

/woocommerce-location-report.php  
  1. class WC_Location_Report { 
  2.  
  3. /** plugin version number */ 
  4. public static $version = '1.2'; 
  5.  
  6. /** @var string the plugin file */ 
  7. public static $plugin_file = __FILE__; 
  8.  
  9. /** @var string the plugin file */ 
  10. public static $plugin_dir; 
  11.  
  12.  
  13. /** 
  14. * Initializes the plugin 
  15. * @since 1.0 
  16. */ 
  17. public function init() { 
  18.  
  19. global $wpdb; 
  20.  
  21. self::$plugin_dir = dirname( __FILE__ ); 
  22.  
  23. // Add any necessary css / scripts 
  24. add_action( 'admin_enqueue_scripts', __CLASS__ . '::location_report_admin_css_scripts' ); 
  25.  
  26. // Add the reports layout to the WooCommerce -> Reports admin section 
  27. add_filter( 'woocommerce_admin_reports', __CLASS__ . '::initialize_location_admin_report', 12, 1 ); 
  28.  
  29. // Add the path to the report class so WooCommerce can parse it 
  30. add_filter( 'wc_admin_reports_path', __CLASS__ . '::initialize_location_admin_reports_path', 12, 3 ); 
  31.  
  32. // Load translation files 
  33. add_action( 'plugins_loaded', __CLASS__ . '::load_plugin_textdomain' ); 
  34.  
  35.  
  36.  
  37. /** 
  38. * Add any location report javascript & css to the admin pages. Only 
  39. * add it to our specific report areas. 
  40. * @since 1.0 
  41. */ 
  42. public static function location_report_admin_css_scripts() { 
  43.  
  44. $wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce' ) ); 
  45. $screen = get_current_screen(); 
  46.  
  47. if ( in_array( $screen->id, apply_filters( 'woocommerce_geo_reports_screen_ids', array( $wc_screen_id . '_page_wc-reports' ) ) ) && isset( $_REQUEST['report'] ) && in_array( $_REQUEST['report'], apply_filters( 'woocommerce_geo_reports_report_ids', array( 'sales_by_location' ) ) ) ) { 
  48.  
  49. //jVector includes - needs to be done in the footer so we can localize data as part of the report generation 
  50. wp_enqueue_script( 'jvectormap', plugins_url( '/lib/jquery-jvectormap-2.0.3.min.js', self::$plugin_file ), array( 'jquery' ), self::$version, true ); 
  51. wp_enqueue_script( 'jvectormap-world', plugins_url( '/lib/map-data/jquery-jvectormap-world-mill.js', self::$plugin_file ), array( 'jquery', 'jvectormap' ), self::$version, true ); 
  52.  
  53. //jVector css 
  54. wp_enqueue_style( 'jvectormap', plugins_url( '/lib/jquery-jvectormap-2.0.3.css', self::$plugin_file ), array( 'woocommerce_admin_styles' ), self::$version ); 
  55.  
  56.  
  57.  
  58.  
  59. /** 
  60. * Add our location report to the WooCommerce order reports array. 
  61. * @param array Array of All Report types & their labels 
  62. * @return array Array of All Report types & their labels, including the 'Sales by location' report. 
  63. * @since 1.0 
  64. */ 
  65. public static function initialize_location_admin_report( $report ) { 
  66.  
  67. $report['orders']['reports']['sales_by_location'] = array( 
  68. 'title' => __( 'Sales by location', 'woocommerce-location-report' ),  
  69. 'description' => '',  
  70. 'hide_title' => true,  
  71. 'callback' => array( 'WC_Admin_Reports', 'get_report' ),  
  72. ); 
  73.  
  74. return $report; 
  75.  
  76.  
  77.  
  78. /** 
  79. * If we hit one of our reports in the WC get_report function, change the path to our dir. 
  80. * @param array Array of Report types & their labels 
  81. * @return array Array of Report types & their labels, including the Subscription product type. 
  82. * @since 1.0 
  83. */ 
  84. public static function initialize_location_admin_reports_path( $report_path, $name, $class ) { 
  85.  
  86. if ( 'WC_Report_sales_by_location' == $class ) { 
  87. $report_path = self::$plugin_dir . '/classes/class-wc-report-' . $name . '.php'; 
  88.  
  89. return $report_path; 
  90.  
  91.  
  92.  
  93. /** 
  94. * Load our language settings for internationalization 
  95. * @since 1.0 
  96. */ 
  97. public static function load_plugin_textdomain() { 
  98.  
  99. load_plugin_textdomain( 'woocommerce-location-report', false, basename( self::$plugin_dir ) . '/languages' ); 
  100.  
  101. } // end \WC_Location_Report class