Skip to content

Commit 45ca924

Browse files
committed
v2.9.1
1 parent 721a460 commit 45ca924

File tree

4 files changed

+85
-64
lines changed

4 files changed

+85
-64
lines changed

custom-emails-for-woocommerce.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Additional Custom Emails for WooCommerce
44
Plugin URI: https://wpfactory.com/item/custom-emails-for-woocommerce/
55
Description: Add custom emails to WooCommerce.
6-
Version: 2.9.0
6+
Version: 2.9.1
77
Author: WPFactory
88
Author URI: https://wpfactory.com
99
Text Domain: custom-emails-for-woocommerce
@@ -30,7 +30,7 @@
3030
}
3131
}
3232

33-
defined( 'ALG_WC_CUSTOM_EMAILS_VERSION' ) || define( 'ALG_WC_CUSTOM_EMAILS_VERSION', '2.9.0' );
33+
defined( 'ALG_WC_CUSTOM_EMAILS_VERSION' ) || define( 'ALG_WC_CUSTOM_EMAILS_VERSION', '2.9.1' );
3434

3535
defined( 'ALG_WC_CUSTOM_EMAILS_FILE' ) || define( 'ALG_WC_CUSTOM_EMAILS_FILE', __FILE__ );
3636

includes/classes/class-alg-wc-custom-email.php

+58-43
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Custom Emails for WooCommerce - Custom Email Class
44
*
5-
* @version 2.9.0
5+
* @version 2.9.1
66
* @since 1.0.0
77
*
88
* @author Algoritmika Ltd
@@ -101,29 +101,6 @@ function __construct( $id = 1 ) {
101101

102102
}
103103

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-
127104
/**
128105
* Get email attachments.
129106
*
@@ -159,16 +136,6 @@ function get_attachments() {
159136

160137
}
161138

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-
172139
/**
173140
* get_content_html.
174141
*
@@ -217,6 +184,39 @@ function init_form_fields() {
217184
$this->form_fields = alg_wc_custom_emails()->core->email_settings->get_form_fields( $this );
218185
}
219186

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+
220220
/**
221221
* alg_wc_ce_admin_settings_tools.
222222
*
@@ -291,17 +291,17 @@ function alg_wc_ce_trigger( $object_id ) {
291291
}
292292

293293
/**
294-
* schedule_single.
294+
* alg_wc_ce_schedule_single.
295295
*
296-
* @version 2.7.0
296+
* @version 2.9.1
297297
* @since 2.7.0
298298
*
299299
* @see https://developer.wordpress.org/reference/functions/wp_schedule_single_event/
300300
* @see https://actionscheduler.org/api/
301301
*
302302
* @todo (dev) `alg_wc_custom_emails_scheduler`: default to `as`
303303
*/
304-
function schedule_single( $timestamp, $hook, $args ) {
304+
function alg_wc_ce_schedule_single( $timestamp, $hook, $args ) {
305305
$scheduler = get_option( 'alg_wc_custom_emails_scheduler', 'wp_cron' );
306306
if ( 'wp_cron' === $scheduler ) {
307307
wp_schedule_single_event( $timestamp, $hook, $args );
@@ -310,10 +310,20 @@ function schedule_single( $timestamp, $hook, $args ) {
310310
}
311311
}
312312

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+
313323
/**
314324
* alg_wc_ce_send_email.
315325
*
316-
* @version 2.9.0
326+
* @version 2.9.1
317327
* @since 1.3.0
318328
*
319329
* @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 = '' ) {
348358
if ( ! $do_force_send && ! empty( $this->alg_wc_ce_delay ) ) {
349359
$class = str_replace( 'alg_wc_custom', 'Alg_WC_Custom_Email', $this->id );
350360
$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 ) );
352363
$this->alg_wc_ce_debug( sprintf( __( 'Delayed (%s): In %d seconds.', 'custom-emails-for-woocommerce' ), $class, $delay ) );
353364
return;
354365
}
@@ -430,6 +441,9 @@ function alg_wc_ce_send_email( $object_id, $do_force_send, $note = '' ) {
430441
$this->get_attachments()
431442
);
432443

444+
// Action
445+
do_action( 'alg_wc_custom_emails_email_sent', $this );
446+
433447
// Debug
434448
$this->alg_wc_ce_debug( sprintf( __( 'Sent: %s', 'custom-emails-for-woocommerce' ),
435449
( $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 = '' ) {
441455
/**
442456
* alg_wc_ce_get_style.
443457
*
444-
* @version 2.7.1
458+
* @version 2.9.1
445459
* @since 2.7.1
446460
*/
447461
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>" : '' );
449463
}
450464

451465
/**
452466
* alg_wc_ce_do_send.
453467
*
454-
* @version 2.0.0
468+
* @version 2.9.1
455469
* @since 1.9.6
456470
*/
457471
function alg_wc_ce_do_send() {
@@ -464,7 +478,8 @@ function alg_wc_ce_do_send() {
464478
}
465479

466480
// 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 ) {
468483
$exclude_recipients = array_filter( array_map( 'trim', explode( ',', str_replace( PHP_EOL, ',', $exclude_recipients ) ) ) );
469484
foreach ( $exclude_recipients as $exclude_recipient ) {
470485
if ( $exclude_recipient === $this->get_recipient() || $this->alg_wc_ce_wildcard_match( $exclude_recipient, $this->get_recipient() ) ) {

langs/custom-emails-for-woocommerce.pot

+17-17
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,16 @@ msgstr ""
238238
msgid "Maximum order amount"
239239
msgstr ""
240240

241-
#: includes/classes/class-alg-wc-custom-email.php:148
241+
#: includes/classes/class-alg-wc-custom-email.php:125
242242
#, php-format
243243
msgid "Email attachment: %s [%s]."
244244
msgstr ""
245245

246-
#: includes/classes/class-alg-wc-custom-email.php:151
246+
#: includes/classes/class-alg-wc-custom-email.php:128
247247
msgid "ok"
248248
msgstr ""
249249

250-
#: includes/classes/class-alg-wc-custom-email.php:152
250+
#: includes/classes/class-alg-wc-custom-email.php:129
251251
msgid "does not exist!"
252252
msgstr ""
253253

@@ -260,65 +260,65 @@ msgstr ""
260260
msgid "Your settings have been reset."
261261
msgstr ""
262262

263-
#: includes/classes/class-alg-wc-custom-email.php:334
263+
#: includes/classes/class-alg-wc-custom-email.php:344
264264
#, php-format
265265
msgid "Triggered [%s]."
266266
msgstr ""
267267

268-
#: includes/classes/class-alg-wc-custom-email.php:343
268+
#: includes/classes/class-alg-wc-custom-email.php:353
269269
msgid "Disabled."
270270
msgstr ""
271271

272-
#: includes/classes/class-alg-wc-custom-email.php:352
272+
#: includes/classes/class-alg-wc-custom-email.php:363
273273
#, php-format
274274
msgid "Delayed (%s): In %d seconds."
275275
msgstr ""
276276

277-
#: includes/classes/class-alg-wc-custom-email.php:377
277+
#: includes/classes/class-alg-wc-custom-email.php:388
278278
#, php-format
279279
msgid "Product #%s."
280280
msgstr ""
281281

282-
#: includes/classes/class-alg-wc-custom-email.php:388
282+
#: includes/classes/class-alg-wc-custom-email.php:399
283283
#, php-format
284284
msgid "Order #%s."
285285
msgstr ""
286286

287-
#: includes/classes/class-alg-wc-custom-email.php:392
288-
#: includes/classes/class-alg-wc-custom-email.php:461
287+
#: includes/classes/class-alg-wc-custom-email.php:403
288+
#: includes/classes/class-alg-wc-custom-email.php:475
289289
#, php-format
290290
msgid "Blocked by the \"%s\" filter."
291291
msgstr ""
292292

293-
#: includes/classes/class-alg-wc-custom-email.php:414
293+
#: includes/classes/class-alg-wc-custom-email.php:425
294294
#, php-format
295295
msgid "Sending \"%s\" email."
296296
msgstr ""
297297

298-
#: includes/classes/class-alg-wc-custom-email.php:415
298+
#: includes/classes/class-alg-wc-custom-email.php:426
299299
#, php-format
300300
msgid "Description: %s."
301301
msgstr ""
302302

303-
#: includes/classes/class-alg-wc-custom-email.php:434
303+
#: includes/classes/class-alg-wc-custom-email.php:448
304304
#, php-format
305305
msgid "Sent: %s"
306306
msgstr ""
307307

308-
#: includes/classes/class-alg-wc-custom-email.php:435
308+
#: includes/classes/class-alg-wc-custom-email.php:449
309309
msgid "success"
310310
msgstr ""
311311

312-
#: includes/classes/class-alg-wc-custom-email.php:435
312+
#: includes/classes/class-alg-wc-custom-email.php:449
313313
msgid "failed"
314314
msgstr ""
315315

316-
#: includes/classes/class-alg-wc-custom-email.php:471
316+
#: includes/classes/class-alg-wc-custom-email.php:486
317317
#, php-format
318318
msgid "Blocked by the \"%s\" option."
319319
msgstr ""
320320

321-
#: includes/classes/class-alg-wc-custom-email.php:472
321+
#: includes/classes/class-alg-wc-custom-email.php:487
322322
#: includes/settings/class-alg-wc-custom-email-settings.php:819
323323
msgid "Exclude recipients"
324324
msgstr ""

readme.txt

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: wpcodefactory, algoritmika, anbinder, karzin, omardabbas, kousikmu
33
Tags: woocommerce, emails, email, custom email, custom emails, woo commerce
44
Requires at least: 4.4
55
Tested up to: 6.4
6-
Stable tag: 2.9.0
6+
Stable tag: 2.9.1
77
License: GNU General Public License v3.0
88
License URI: http://www.gnu.org/licenses/gpl-3.0.html
99

@@ -146,10 +146,16 @@ Dive in and discover more tools to empower your WooCommerce Store!
146146

147147
== Changelog ==
148148

149+
= 2.9.1 - 29/02/2024 =
150+
* Dev - Developers - `alg_wc_custom_emails_delay_start_time` filter added.
151+
* Dev - Developers - `alg_wc_custom_emails_email_sent` action added.
152+
* Dev - Developers - `alg_wc_custom_emails_exclude_recipients` filter added.
153+
* Dev - Code refactoring.
154+
149155
= 2.9.0 - 21/02/2024 =
150156
* Dev - Order Options - Require/Exclude order status - "WooCommerce Subscriptions" statuses added.
151157
* Dev - Shortcodes - `[order_checkout_payment_url]` shortcode added.
152-
* Dev - Send email - Now trying to get object ID with the `get_id()` method (e.g., for "WooCommerce Subscriptions" status updated hooks).
158+
* Dev - Send email - Now trying to get object ID with the `get_id()` method (e.g., for "WooCommerce Subscriptions" status update hooks).
153159
* Typos fixed in the plugin description section in readme.txt.
154160
* WC tested up to: 8.6.
155161

0 commit comments

Comments
 (0)