@@ -15,11 +15,6 @@ class WCS_Action_Scheduler_Customer_Notifications extends WCS_Scheduler {
15
15
*/
16
16
protected int $ hours_offset ;
17
17
18
- /**
19
- * @var DateInterval Time offset between the notification and the action it's notifying about.
20
- */
21
- protected DateInterval $ time_delta ;
22
-
23
18
/**
24
19
* @var array|string[] Notifications scheduled by this class.
25
20
*
@@ -32,13 +27,26 @@ class WCS_Action_Scheduler_Customer_Notifications extends WCS_Scheduler {
32
27
'woocommerce_scheduled_subscription_customer_notification_auto_renewal ' ,
33
28
);
34
29
30
+ public function get_hours_offset () {
31
+ /**
32
+ * Offset between a subscription event and related notification.
33
+ *
34
+ * @since 8.0.0
35
+ *
36
+ * @param int $hours_offset
37
+ */
38
+ return apply_filters ( 'woocommerce_subscriptions_customer_notification_hours_offset ' , $ this ->hours_offset );
39
+ }
40
+
41
+ public function set_hours_offset ( $ hours_offset ) {
42
+ $ this ->hours_offset = $ hours_offset ;
43
+ }
44
+
35
45
public function __construct () {
36
46
parent ::__construct ();
37
47
38
48
//TODO: make number of hours configurable.
39
49
$ this ->hours_offset = 3 * DAY_IN_SECONDS / HOUR_IN_SECONDS ; // aka 3 days in hours.
40
-
41
- $ this ->time_delta = new DateInterval ( "PT {$ this ->hours_offset }H " );
42
50
}
43
51
44
52
public function set_date_types_to_schedule () {
@@ -87,7 +95,7 @@ protected function schedule_notification( $subscription, $action, $timestamp ) {
87
95
*/
88
96
protected function sub_time_offset ( $ datetime ) {
89
97
$ dt = new DateTime ( $ datetime , new DateTimeZone ( 'UTC ' ) );
90
- $ dt ->sub ( $ this ->time_delta );
98
+ $ dt ->sub ( new DateInterval ( " PT { $ this ->get_hours_offset ()} H " ) );
91
99
92
100
return $ dt ->getTimestamp ();
93
101
}
0 commit comments