This repository has been archived by the owner on Sep 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwoocommerce-location-report.php
161 lines (121 loc) · 4.98 KB
/
woocommerce-location-report.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
/**
* Plugin Name: WooCommerce Sales By Location Report
* Plugin URI: http://chuckmacdev.com
* Description: WooCommerce report to visualize sales by location.
* Author: ChuckMac Development
* Author URI: http://chuckmacdev.com
* Version: 1.3.2
* Text Domain: wc_location_report
* Domain Path: /languages/
*
* Copyright: (c) 2014-2015 ChuckMac Development LLC
*
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*
* @package WC-Location-Report
* @author WooThemes
* @category Reports
* @copyright Copyright (c) 2014-2015, ChuckMac Development LLC
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
// Check if WooCommerce is active
if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
return;
}
/**
* # WooCommerce Location Report Main Plugin Class
*
* ## Plugin Overview
*
* This plugin adds a new section in the WooCommerce Reports -> Orders area called 'Sales by location'.
* The report visualizes the customer purchases by location into a Choropleth map to show where the orders
* are being placed.
*
* This plugin utilizes jVectorMap (http://jvectormap.com) for its map functions.
*
*/
class WC_Location_Report {
/** plugin version number */
public static $version = '1.3.2';
/** @var string the plugin file */
public static $plugin_file = __FILE__;
/** @var string the plugin file */
public static $plugin_dir;
/**
* Initializes the plugin
*
* @since 1.0
*/
public static function init() {
global $wpdb;
self::$plugin_dir = dirname( __FILE__ );
// Add any necessary css / scripts
add_action( 'admin_enqueue_scripts', __CLASS__ . '::location_report_admin_css_scripts' );
// Add the reports layout to the WooCommerce -> Reports admin section
add_filter( 'woocommerce_admin_reports', __CLASS__ . '::initialize_location_admin_report', 12, 1 );
// Add the path to the report class so WooCommerce can parse it
add_filter( 'wc_admin_reports_path', __CLASS__ . '::initialize_location_admin_reports_path', 12, 3 );
// Load translation files
add_action( 'plugins_loaded', __CLASS__ . '::load_plugin_textdomain' );
}
/**
* Add any location report javascript & css to the admin pages. Only
* add it to our specific report areas.
*
* @since 1.0
*/
public static function location_report_admin_css_scripts() {
$wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce' ) );
$screen = get_current_screen();
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' ) ) ) ) {
//jVector includes - needs to be done in the footer so we can localize data as part of the report generation
wp_enqueue_script( 'jvectormap', plugins_url( '/lib/jquery-jvectormap-2.0.3.min.js', self::$plugin_file ), array( 'jquery' ), self::$version, true );
wp_enqueue_script( 'jvectormap-world', plugins_url( '/lib/map-data/jquery-jvectormap-world-mill.js', self::$plugin_file ), array( 'jquery', 'jvectormap' ), self::$version, true );
//jVector css
wp_enqueue_style( 'jvectormap', plugins_url( '/lib/jquery-jvectormap-2.0.3.css', self::$plugin_file ), array( 'woocommerce_admin_styles' ), self::$version );
}
}
/**
* Add our location report to the WooCommerce order reports array.
*
* @param array Array of All Report types & their labels
* @return array Array of All Report types & their labels, including the 'Sales by location' report.
* @since 1.0
*/
public static function initialize_location_admin_report( $report ) {
$report['orders']['reports']['sales_by_location'] = array(
'title' => __( 'Sales by location', 'woocommerce-location-report' ),
'description' => '',
'hide_title' => true,
'callback' => array( 'WC_Admin_Reports', 'get_report' ),
);
return $report;
}
/**
* If we hit one of our reports in the WC get_report function, change the path to our dir.
*
* @param array Array of Report types & their labels
* @return array Array of Report types & their labels, including the Subscription product type.
* @since 1.0
*/
public static function initialize_location_admin_reports_path( $report_path, $name, $class ) {
if ( 'WC_Report_sales_by_location' == $class ) {
$report_path = self::$plugin_dir . '/classes/class-wc-report-' . $name . '.php';
}
return $report_path;
}
/**
* Load our language settings for internationalization
*
* @since 1.0
*/
public static function load_plugin_textdomain() {
load_plugin_textdomain( 'woocommerce-location-report', false, basename( self::$plugin_dir ) . '/languages' );
}
} // end \WC_Location_Report class
WC_Location_Report::init();