-
Notifications
You must be signed in to change notification settings - Fork 1
/
woocommerce-sales-report-email.php
225 lines (181 loc) · 5.25 KB
/
woocommerce-sales-report-email.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<?php
/*
Plugin Name: WooCommerce Sales Report Email
Plugin URI: http://www.woothemes.com/products/woocommerce-sales-report-email/
Description: Daily Sales Report Email
Version: 1.1.2
Author: WooThemes
Author URI: http://www.woothemes.com/
License: GPL v3
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Required functions
*/
if ( ! function_exists( 'woothemes_queue_update' ) ) {
require_once( plugin_dir_path( __FILE__ ) . '/woo-includes/woo-functions.php' );
}
/**
* Plugin updates
*/
woothemes_queue_update( plugin_basename( __FILE__ ), 'a276a32606bc06fc451666a02c52cc64', '473579' );
class WooCommerce_Sales_Report_Email {
/**
* Get the plugin file
*
* @access public
* @static
* @since 1.0.0
* @return String
*/
public static function get_plugin_file() {
return __FILE__;
}
/**
* A static method that will setup the autoloader
*
* @access private
* @since 1.0.0
*/
private static function setup_autoloader() {
require_once( plugin_dir_path( self::get_plugin_file() ) . '/classes/class-wc-sre-autoloader.php' );
$autoloader = new WC_SRE_Autoloader( plugin_dir_path( self::get_plugin_file() ) . 'classes/' );
spl_autoload_register( array( $autoloader, 'load' ) );
}
/**
* This method will be run on plugin activation
*
* @access public
* @since 1.0.0
*/
public static function activation() {
// Setup the autoloader
self::setup_autoloader();
// Setup Cron
$cron_manager = new WC_SRE_Cron_Manager();
$cron_manager->setup_cron();
}
/**
* This method wil run on plugin deactivation
*
* @access public
* @since 1.0.0
*/
public static function deativation() {
// Setup the autoloader
self::setup_autoloader();
// Remove Cron
$cron_manager = new WC_SRE_Cron_Manager();
$cron_manager->remove_cron();
}
/**
* Constructor
*
* @access public
* @since 1.0.0
*/
public function __construct() {
// Check if WC is activated
if ( $this->is_wc_active() ) {
$this->init();
}
}
/**
* Check if WooCommerce is active
*
* @access private
* @since 1.0.0
* @return bool
*/
private function is_wc_active() {
$is_active = WC_Dependencies::woocommerce_active_check();
// Do the WC active check
if ( false === $is_active ) {
add_action( 'admin_notices', array( $this, 'notice_activate_wc' ) );
}
return $is_active;
}
/**
* Initialize the plugin
*
* @access private
* @since 1.0.0
*/
private function init() {
// Load plugin textdomain
load_plugin_textdomain( 'woocommerce-sales-report-email', false, plugin_dir_path( self::get_plugin_file() ) . 'languages/' );
// save email settings
add_action( 'woocommerce_settings_saved', array( $this, 'reset_cron' ) );
// Setup the autoloader
self::setup_autoloader();
// Only load in admin
if ( is_admin() ) {
// Setup the settings
$settings = new WC_SRE_Settings();
$settings->setup();
}
// Cron hook
add_action( WC_SRE_Cron_Manager::CRON_HOOK, array( $this, 'cron_email_callback' ) );
}
/**
* Method triggered on saving admin sales report email settings
* This is to make sure the time_sent parameter gets changed in the sheduled event.
*
* @access public
* @since 1.1.0
*/
public function reset_cron() {
if ( isset( $_REQUEST[ 'woocommerce_sales_report_email_send_time' ] ) && strlen( $_REQUEST[ 'woocommerce_sales_report_email_send_time' ] > 0 ) ) {
$cron_manager = new WC_SRE_Cron_Manager();
$cron_manager->remove_cron();
$cron_manager->setup_cron();
}
}
/**
* Method triggered on Cron run.
* This method will create a WC_SRE_Sales_Report_Email object and call trigger method.
*
* @access public
* @since 1.0.0
*/
public function cron_email_callback() {
WC()->mailer();
// This will be a WP Cron action
$email = new WC_SRE_Sales_Report_Email();
$email->trigger();
}
/**
* Display the WC
*
* @access public
* @since 1.0.0
*/
public function notice_activate_wc() {
?>
<div class="error">
<p><?php printf( __( 'Please install and activate %sWooCommerce%s for WooCommerce Sales Report Email to work!', 'woocommerce-sales-report-email' ), '<a href="' . admin_url( 'plugin-install.php?tab=search&s=WooCommerce&plugin-search-input=Search+Plugins' ) . '">', '</a>' ); ?></p>
</div>
<?php
}
}
function __woocommerce_sales_report_email_main() {
new WooCommerce_Sales_Report_Email();
}
// Create object - Plugin init
add_action( 'plugins_loaded', '__woocommerce_sales_report_email_main' );
// Activation hook
register_activation_hook( __FILE__, array( 'WooCommerce_Sales_Report_Email', 'activation' ) );
// Deactivation hook
register_deactivation_hook( __FILE__, array( 'WooCommerce_Sales_Report_Email', 'deactivation' ) );