Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit b614a4e

Browse files
committed
Add get/setter for hours offset and a filter.
1 parent ab9085e commit b614a4e

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

includes/class-wcs-action-scheduler-customer-notifications.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ class WCS_Action_Scheduler_Customer_Notifications extends WCS_Scheduler {
1515
*/
1616
protected int $hours_offset;
1717

18-
/**
19-
* @var DateInterval Time offset between the notification and the action it's notifying about.
20-
*/
21-
protected DateInterval $time_delta;
22-
2318
/**
2419
* @var array|string[] Notifications scheduled by this class.
2520
*
@@ -32,13 +27,26 @@ class WCS_Action_Scheduler_Customer_Notifications extends WCS_Scheduler {
3227
'woocommerce_scheduled_subscription_customer_notification_auto_renewal',
3328
);
3429

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+
3545
public function __construct() {
3646
parent::__construct();
3747

3848
//TODO: make number of hours configurable.
3949
$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" );
4250
}
4351

4452
public function set_date_types_to_schedule() {
@@ -87,7 +95,7 @@ protected function schedule_notification( $subscription, $action, $timestamp ) {
8795
*/
8896
protected function sub_time_offset( $datetime ) {
8997
$dt = new DateTime( $datetime, new DateTimeZone( 'UTC' ) );
90-
$dt->sub( $this->time_delta );
98+
$dt->sub( new DateInterval( "PT{$this->get_hours_offset()}H" ) );
9199

92100
return $dt->getTimestamp();
93101
}

0 commit comments

Comments
 (0)