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

Commit 6afaabe

Browse files
committed
Merge branch 'try/subs-notifications-pf' of https://github.com/Automattic/woocommerce-subscriptions-core into try/subs-notifications-pf
2 parents 707a4d2 + e43558e commit 6afaabe

File tree

3 files changed

+55
-7
lines changed

3 files changed

+55
-7
lines changed

changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
*** WooCommerce Subscriptions Core Changelog ***
22

3+
= 7.4.0 - 2024-xx-xx =
4+
* Update - Schedule subscription-related events with a priority of 1 to allow for earlier execution within the Action Scheduler.
5+
* Fix - Ensure admin notices are displayed after performing bulk actions on subscriptions when HPOS is enabled.
6+
37
= 7.3.0 - 2024-07-16 =
48
* Fix - Label improvements on subscription and order page templates.
59
* Fix - Fixed an issue with subscriptions containing multiple renewal orders to mark a random item as processing, instead of the last order.

includes/class-wcs-action-scheduler.php

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
*/
1111
class WCS_Action_Scheduler extends WCS_Scheduler {
1212

13+
/**
14+
* The action scheduler group to use for scheduled subscription events.
15+
*/
16+
const ACTION_GROUP = 'wc_subscription_scheduled_event';
17+
18+
/**
19+
* The priority of the subscription-related scheduled action.
20+
*/
21+
const ACTION_PRIORITY = 1;
22+
1323
/**
1424
* An internal cache of action hooks and corresponding date types.
1525
*
@@ -55,7 +65,7 @@ public function update_date( $subscription, $date_type, $datetime ) {
5565

5666
// Only schedule it if it's valid. It's active, it's a payment retry or it's pending cancelled and the end date being updated.
5767
if ( 'payment_retry' === $date_type || $subscription->has_status( 'active' ) || ( $subscription->has_status( 'pending-cancel' ) && 'end' === $date_type ) ) {
58-
as_schedule_single_action( $timestamp, $action_hook, $action_args );
68+
$this->schedule_action( $timestamp, $action_hook, $action_args );
5969
}
6070
}
6171
}
@@ -110,7 +120,7 @@ public function update_status( $subscription, $new_status, $old_status ) {
110120
}
111121

112122
if ( 0 != $event_time && $event_time > current_time( 'timestamp', true ) && $next_scheduled !== $event_time ) {
113-
as_schedule_single_action( $event_time, $action_hook, $action_args );
123+
$this->schedule_action( $event_time, $action_hook, $action_args );
114124
}
115125
}
116126

@@ -139,7 +149,7 @@ public function update_status( $subscription, $new_status, $old_status ) {
139149

140150
// The end date was set in WC_Subscriptions::update_dates() to the appropriate value, so we can schedule our action for that time
141151
if ( $end_time > current_time( 'timestamp', true ) && $next_scheduled !== $end_time ) {
142-
as_schedule_single_action( $end_time, 'woocommerce_scheduled_subscription_end_of_prepaid_term', $action_args );
152+
$this->schedule_action( $end_time, 'woocommerce_scheduled_subscription_end_of_prepaid_term', $action_args );
143153
}
144154
break;
145155
case 'on-hold':
@@ -226,4 +236,36 @@ protected function get_action_args( $date_type, $subscription ) {
226236
protected function unschedule_actions( $action_hook, $action_args ) {
227237
as_unschedule_all_actions( $action_hook, $action_args );
228238
}
239+
240+
/**
241+
* Gets the priority of the subscription-related scheduled action.
242+
*
243+
* @return int The priority of the subscription-related scheduled action.
244+
*/
245+
public function get_action_priority( $action_hook ) {
246+
return apply_filters( 'woocommerce_subscriptions_scheduled_action_priority', self::ACTION_PRIORITY, $action_hook );
247+
}
248+
249+
/**
250+
* Schedule an subscription-related action with the Action Scheduler.
251+
*
252+
* Subscription events are scheduled with a priority of 1 (see self::ACTION_PRIORITY) and the
253+
* group 'wc_subscription_scheduled_event' (see self::ACTION_GROUP).
254+
*
255+
* @param int $timestamp Unix timestamp of when the action should run.
256+
* @param string $action_hook Name of event used as the hook for the scheduled action.
257+
* @param array $action_args Array of name => value pairs stored against the scheduled action.
258+
*
259+
* @return int The action ID.
260+
*/
261+
protected function schedule_action( $timestamp, $action_hook, $action_args ) {
262+
$as_version = ActionScheduler_Versions::instance()->latest_version();
263+
264+
// On older versions of Action Scheduler, we cannot specify a priority.
265+
if ( version_compare( $as_version, '3.6.0', '<' ) ) {
266+
return as_schedule_single_action( $timestamp, $action_hook, $action_args, self::ACTION_GROUP );
267+
}
268+
269+
return as_schedule_single_action( $timestamp, $action_hook, $action_args, self::ACTION_GROUP, false, $this->get_action_priority( $action_hook ) );
270+
}
229271
}

includes/privacy/class-wcs-privacy.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public static function add_privacy_bulk_action( $bulk_actions ) {
124124
*/
125125
public static function handle_privacy_bulk_actions( $redirect_url, $action, $subscription_ids ) {
126126
if ( 'wcs_remove_personal_data' !== $action ) {
127-
return;
127+
return $redirect_url;
128128
}
129129

130130
$changed = 0;
@@ -146,8 +146,7 @@ public static function handle_privacy_bulk_actions( $redirect_url, $action, $sub
146146
$sendback_args['changed'] = $changed;
147147
$sendback = add_query_arg( $sendback_args, $redirect_url );
148148

149-
wp_safe_redirect( esc_url_raw( $sendback ) );
150-
exit();
149+
return esc_url_raw( $sendback );
151150
}
152151

153152
/**
@@ -178,7 +177,10 @@ public static function process_bulk_action() {
178177
$subscription_ids = array_map( 'absint', (array) $_REQUEST['post'] );
179178
$base_redirect_url = wp_get_referer() ? wp_get_referer() : '';
180179

181-
self::handle_privacy_bulk_actions( $base_redirect_url, $action, $subscription_ids );
180+
$redirect_url = self::handle_privacy_bulk_actions( $base_redirect_url, $action, $subscription_ids );
181+
182+
wp_safe_redirect( $redirect_url );
183+
exit();
182184
}
183185

184186
/**

0 commit comments

Comments
 (0)