2
2
/**
3
3
* Custom Emails for WooCommerce - Custom Email Class
4
4
*
5
- * @version 2.9.0
5
+ * @version 2.9.1
6
6
* @since 1.0.0
7
7
*
8
8
* @author Algoritmika Ltd
@@ -101,29 +101,6 @@ function __construct( $id = 1 ) {
101
101
102
102
}
103
103
104
- /**
105
- * alg_wc_ce_stop_email.
106
- *
107
- * @version 2.7.3
108
- * @since 2.7.3
109
- *
110
- * @todo (dev) add all emails, i.e., not only `order`
111
- * @todo (dev) `alg_wc_ce_do_send()`: should include `$this->alg_wc_ce_order_validator->validate( $object )`?
112
- */
113
- function alg_wc_ce_stop_email ( $ is_enabled , $ object ) {
114
- if (
115
- $ is_enabled &&
116
- $ object &&
117
- is_a ( $ object , 'WC_Order ' ) &&
118
- $ this ->is_enabled () &&
119
- $ this ->alg_wc_ce_order_validator ->validate ( $ object ) &&
120
- $ this ->alg_wc_ce_do_send ()
121
- ) {
122
- return false ;
123
- }
124
- return $ is_enabled ;
125
- }
126
-
127
104
/**
128
105
* Get email attachments.
129
106
*
@@ -159,16 +136,6 @@ function get_attachments() {
159
136
160
137
}
161
138
162
- /**
163
- * alg_wc_ce_do_add_header_and_footer.
164
- *
165
- * @version 2.4.0
166
- * @since 2.4.0
167
- */
168
- function alg_wc_ce_do_add_header_and_footer () {
169
- return ( 'yes ' === $ this ->get_option ( 'wrap_in_wc_template ' , 'yes ' ) );
170
- }
171
-
172
139
/**
173
140
* get_content_html.
174
141
*
@@ -217,6 +184,39 @@ function init_form_fields() {
217
184
$ this ->form_fields = alg_wc_custom_emails ()->core ->email_settings ->get_form_fields ( $ this );
218
185
}
219
186
187
+ /**
188
+ * alg_wc_ce_stop_email.
189
+ *
190
+ * @version 2.7.3
191
+ * @since 2.7.3
192
+ *
193
+ * @todo (dev) add all emails, i.e., not only `order`
194
+ * @todo (dev) `alg_wc_ce_do_send()`: should include `$this->alg_wc_ce_order_validator->validate( $object )`?
195
+ */
196
+ function alg_wc_ce_stop_email ( $ is_enabled , $ object ) {
197
+ if (
198
+ $ is_enabled &&
199
+ $ object &&
200
+ is_a ( $ object , 'WC_Order ' ) &&
201
+ $ this ->is_enabled () &&
202
+ $ this ->alg_wc_ce_order_validator ->validate ( $ object ) &&
203
+ $ this ->alg_wc_ce_do_send ()
204
+ ) {
205
+ return false ;
206
+ }
207
+ return $ is_enabled ;
208
+ }
209
+
210
+ /**
211
+ * alg_wc_ce_do_add_header_and_footer.
212
+ *
213
+ * @version 2.4.0
214
+ * @since 2.4.0
215
+ */
216
+ function alg_wc_ce_do_add_header_and_footer () {
217
+ return ( 'yes ' === $ this ->get_option ( 'wrap_in_wc_template ' , 'yes ' ) );
218
+ }
219
+
220
220
/**
221
221
* alg_wc_ce_admin_settings_tools.
222
222
*
@@ -291,17 +291,17 @@ function alg_wc_ce_trigger( $object_id ) {
291
291
}
292
292
293
293
/**
294
- * schedule_single .
294
+ * alg_wc_ce_schedule_single .
295
295
*
296
- * @version 2.7.0
296
+ * @version 2.9.1
297
297
* @since 2.7.0
298
298
*
299
299
* @see https://developer.wordpress.org/reference/functions/wp_schedule_single_event/
300
300
* @see https://actionscheduler.org/api/
301
301
*
302
302
* @todo (dev) `alg_wc_custom_emails_scheduler`: default to `as`
303
303
*/
304
- function schedule_single ( $ timestamp , $ hook , $ args ) {
304
+ function alg_wc_ce_schedule_single ( $ timestamp , $ hook , $ args ) {
305
305
$ scheduler = get_option ( 'alg_wc_custom_emails_scheduler ' , 'wp_cron ' );
306
306
if ( 'wp_cron ' === $ scheduler ) {
307
307
wp_schedule_single_event ( $ timestamp , $ hook , $ args );
@@ -310,10 +310,20 @@ function schedule_single( $timestamp, $hook, $args ) {
310
310
}
311
311
}
312
312
313
+ /**
314
+ * alg_wc_ce_get_delay_start_time.
315
+ *
316
+ * @version 2.9.1
317
+ * @since 2.9.1
318
+ */
319
+ function alg_wc_ce_get_delay_start_time ( $ object_id ) {
320
+ return apply_filters ( 'alg_wc_custom_emails_delay_start_time ' , time (), $ this , $ object_id );
321
+ }
322
+
313
323
/**
314
324
* alg_wc_ce_send_email.
315
325
*
316
- * @version 2.9.0
326
+ * @version 2.9.1
317
327
* @since 1.3.0
318
328
*
319
329
* @todo (dev) `wc_get_product( $object_id )`: better solution, e.g., use `current_filter()`?
@@ -348,7 +358,8 @@ function alg_wc_ce_send_email( $object_id, $do_force_send, $note = '' ) {
348
358
if ( ! $ do_force_send && ! empty ( $ this ->alg_wc_ce_delay ) ) {
349
359
$ class = str_replace ( 'alg_wc_custom ' , 'Alg_WC_Custom_Email ' , $ this ->id );
350
360
$ delay = intval ( $ this ->alg_wc_ce_delay * $ this ->alg_wc_ce_delay_unit );
351
- $ this ->schedule_single ( time () + $ delay , 'alg_wc_custom_emails_send_email ' , array ( $ class , $ object_id ) );
361
+ $ time = $ this ->alg_wc_ce_get_delay_start_time ( $ object_id ) + $ delay ;
362
+ $ this ->alg_wc_ce_schedule_single ( $ time , 'alg_wc_custom_emails_send_email ' , array ( $ class , $ object_id ) );
352
363
$ this ->alg_wc_ce_debug ( sprintf ( __ ( 'Delayed (%s): In %d seconds. ' , 'custom-emails-for-woocommerce ' ), $ class , $ delay ) );
353
364
return ;
354
365
}
@@ -430,6 +441,9 @@ function alg_wc_ce_send_email( $object_id, $do_force_send, $note = '' ) {
430
441
$ this ->get_attachments ()
431
442
);
432
443
444
+ // Action
445
+ do_action ( 'alg_wc_custom_emails_email_sent ' , $ this );
446
+
433
447
// Debug
434
448
$ this ->alg_wc_ce_debug ( sprintf ( __ ( 'Sent: %s ' , 'custom-emails-for-woocommerce ' ),
435
449
( $ res ? __ ( 'success ' , 'custom-emails-for-woocommerce ' ) : __ ( 'failed ' , 'custom-emails-for-woocommerce ' ) ) ) );
@@ -441,17 +455,17 @@ function alg_wc_ce_send_email( $object_id, $do_force_send, $note = '' ) {
441
455
/**
442
456
* alg_wc_ce_get_style.
443
457
*
444
- * @version 2.7 .1
458
+ * @version 2.9 .1
445
459
* @since 2.7.1
446
460
*/
447
461
function alg_wc_ce_get_style () {
448
- return ( ( $ style = $ this ->get_option ( 'alg_wc_ce_style ' , '' ) ) ? "<style> $ style</style> " : '' );
462
+ return ( ( $ style = $ this ->get_option ( 'alg_wc_ce_style ' , '' ) ) ? "<style> { $ style} </style> " : '' );
449
463
}
450
464
451
465
/**
452
466
* alg_wc_ce_do_send.
453
467
*
454
- * @version 2.0.0
468
+ * @version 2.9.1
455
469
* @since 1.9.6
456
470
*/
457
471
function alg_wc_ce_do_send () {
@@ -464,7 +478,8 @@ function alg_wc_ce_do_send() {
464
478
}
465
479
466
480
// Exclude recipients
467
- if ( '' !== ( $ exclude_recipients = $ this ->get_option ( 'exclude_recipients ' , '' ) ) ) {
481
+ $ exclude_recipients = apply_filters ( 'alg_wc_custom_emails_exclude_recipients ' , $ this ->get_option ( 'exclude_recipients ' , '' ), $ this );
482
+ if ( '' !== $ exclude_recipients ) {
468
483
$ exclude_recipients = array_filter ( array_map ( 'trim ' , explode ( ', ' , str_replace ( PHP_EOL , ', ' , $ exclude_recipients ) ) ) );
469
484
foreach ( $ exclude_recipients as $ exclude_recipient ) {
470
485
if ( $ exclude_recipient === $ this ->get_recipient () || $ this ->alg_wc_ce_wildcard_match ( $ exclude_recipient , $ this ->get_recipient () ) ) {
0 commit comments