PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 2.2.0
Subscriptions for WooCommerce with Stripe Recurring Payments v2.2.0
2.4.0 2.3.0 2.2.0 2.1.0 2.0.0 1.11.2 1.11.1 1.11.0 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.6 1.9.5 trunk 1.3.0 1.3.1 1.3.2 1.4.0 All 65 releases
← All changes | includes/Illuminate/Action.php +66 -2 1.9.6 → 2.2.0 View file →
@@ -16,8 +16,19 @@
16 16 * @param int $subscription_id Subscription ID.
17 17 * @param bool $write_comment Write comment?.
18 18 */
19 19 public static function status( string $status, int $subscription_id, bool $write_comment = true ) {
20 + // A split-payment subscription whose final installment is paid is terminal:
21 + // never (re)activate it. Any renewal-payment path that tries to set it active
22 + // after completion is coerced to `completed` so the status can't flip back.
23 + if (
24 + 'active' === $status
25 + && function_exists( 'subscrpt_is_max_payments_reached' )
26 + && subscrpt_is_max_payments_reached( $subscription_id )
27 + ) {
28 + $status = 'completed';
29 + }
30 +
20 31 $old_status = get_post_status( $subscription_id );
21 32
22 33 wp_update_post(
23 34 array(
@@ -25,9 +36,10 @@
25 36 'post_status' => $status,
26 37 )
27 38 );
28 39
29 - if ( $write_comment ) {
40 + // Only note a real transition — never re-log the same status.
41 + if ( $write_comment && $old_status !== $status ) {
30 42 self::write_comment( $status, $subscription_id );
31 43 }
32 44
33 45 // Trigger status change action
@@ -61,12 +73,38 @@
61 73 break;
62 74 case 'pe_cancelled':
63 75 self::pe_cancelled( $subscription_id );
64 76 break;
77 + case 'on-hold':
78 + self::on_hold( $subscription_id );
79 + break;
80 + case 'completed':
81 + self::completed( $subscription_id );
82 + break;
65 83 }
66 84 }
67 85
68 86 /**
87 + * Write Comment About Completed Subscription.
88 + *
89 + * @param int $subscription_id Subscription ID.
90 + */
91 + private static function completed( int $subscription_id ) {
92 + $comment_id = wp_insert_comment(
93 + array(
94 + 'comment_author' => 'Subscription for WooCommerce',
95 + 'comment_content' => 'Subscription completed. All payments made.',
96 + 'comment_post_ID' => $subscription_id,
97 + 'comment_type' => 'order_note',
98 + )
99 + );
100 + update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Completed' );
101 + update_comment_meta( $comment_id, '_subscrpt_activity_type', 'subs_completed' );
102 +
103 + do_action( 'subscrpt_subscription_completed', $subscription_id );
104 + }
105 +
106 + /**
69 107 * Write Comment About expired Subscription.
70 108 *
71 109 * @param int $subscription_id Subscription ID.
72 110 */
@@ -93,9 +131,9 @@
93 131 private static function active( int $subscription_id ) {
94 132 $comment_id = wp_insert_comment(
95 133 array(
96 134 'comment_author' => 'Subscription for WooCommerce',
97 - 'comment_content' => 'Subscription activated.Next payment due date set.',
135 + 'comment_content' => 'Subscription activated. Next payment due date set.',
98 136 'comment_post_ID' => $subscription_id,
99 137 'comment_type' => 'order_note',
100 138 )
101 139 );
@@ -150,8 +188,28 @@
150 188 do_action( 'subscrpt_split_payment_cancelled', $subscription_id );
151 189 }
152 190
153 191 /**
192 + * Write Comment About On-Hold Subscription.
193 + *
194 + * @param int $subscription_id Subscription ID.
195 + */
196 + private static function on_hold( int $subscription_id ) {
197 + $comment_id = wp_insert_comment(
198 + array(
199 + 'comment_author' => 'Subscription for WooCommerce',
200 + 'comment_content' => 'Subscription is On Hold. Access suspended after payment failure.',
201 + 'comment_post_ID' => $subscription_id,
202 + 'comment_type' => 'order_note',
203 + )
204 + );
205 + update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription On Hold' );
206 + update_comment_meta( $comment_id, '_subscrpt_activity_type', 'subs_on_hold' );
207 +
208 + do_action( 'subscrpt_subscription_on_hold', $subscription_id );
209 + }
210 +
211 + /**
154 212 * Write Comment About Pending Cancellation.
155 213 *
156 214 * @param int $subscription_id Subscription ID.
157 215 */
@@ -165,8 +223,14 @@
165 223 )
166 224 );
167 225 update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Pending Cancellation' );
168 226 update_comment_meta( $comment_id, '_subscrpt_activity_type', 'subs_pe_cancel' );
227 +
228 + // WC_Email classes only exist once the mailer has been built, and they
229 + // attach their own listeners from their constructors. Without this, an
230 + // email listening for a pending cancellation is simply not registered yet
231 + // when the action fires - the same reason cancelled() calls it.
232 + WC()->mailer();
169 233
170 234 do_action( 'subscrpt_subscription_pending_cancellation', $subscription_id );
171 235 }
172 236 }