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/Order.php +35 -88 1.11.2 → 2.2.0 View file →
@@ -84,8 +84,17 @@
84 84
85 85 $next_date = sdevs_wp_strtotime( $recurr_timing, time() );
86 86 }
87 87
88 + // Split payment: no next date after the final installment.
89 + if (
90 + in_array( $subscription_history->type, array( 'renew', 'early-renew' ), true )
91 + && function_exists( 'subscrpt_is_max_payments_reached' )
92 + && subscrpt_is_max_payments_reached( $subscription_id )
93 + ) {
94 + return;
95 + }
96 +
88 97 /**
89 98 * Filter the subscription next payment date before it is saved.
90 99 *
91 100 * General-purpose hook (not scoped to split payment) for adjusting the
@@ -263,12 +272,36 @@
263 272
264 273 foreach ( $histories as $history ) {
265 274 if ( 'new' === $history->type || 'renew' === $history->type ) {
266 275 $subscription_id = $history->subscription_id;
276 +
277 + // Renewals ignore the intermediate `processing` state for renewal orders.
278 + if ( 'renew' === $history->type && 'processing' === $order->get_status() ) {
279 + continue;
280 + }
281 +
282 + // Capture the status before the max-payments check below may flip it.
283 + $current_status = get_post_status( $subscription_id );
284 +
285 + // Split payment: complete instead of re-activate after the final installment.
286 + $target_status = $post_status;
287 + if (
288 + 'active' === $target_status
289 + && function_exists( 'subscrpt_is_max_payments_reached' )
290 + && subscrpt_is_max_payments_reached( $subscription_id )
291 + ) {
292 + $target_status = 'completed';
293 + }
294 +
295 + // Skip no-op transitions so the note and side effects don't duplicate.
296 + if ( $current_status === $target_status ) {
297 + continue;
298 + }
299 +
267 300 wp_update_post(
268 301 array(
269 302 'ID' => $subscription_id,
270 - 'post_status' => $post_status,
303 + 'post_status' => $target_status,
271 304 )
272 305 );
273 306
274 307 // If possible change order status to completed if it has a trial subscription.
@@ -283,9 +316,9 @@
283 316
284 317 // Add enhanced split payment activity logging
285 318 $this->add_split_payment_activity_note( $history->subscription_id, $history->type, $post_status, $order );
286 319
287 - Action::write_comment( $post_status, $history->subscription_id );
320 + Action::write_comment( $target_status, $history->subscription_id );
288 321 } else {
289 322 do_action( 'subscrpt_order_status_changed', $order, $history );
290 323 }
291 324 }
@@ -396,94 +429,8 @@
396 429 $max_payments,
397 430 $subscription_id
398 431 );
399 432 $order->add_order_note( $order_note );
400 - }
401 -
402 - // Add payment milestone notes for significant progress
403 - $this->add_payment_milestone_notes( $subscription_id, $payments_made, $max_payments );
404 - }
405 -
406 - /**
407 - * Add payment milestone notes for significant progress (25%, 50%, 75%, 100%).
408 - *
409 - * @param int $subscription_id Subscription ID.
410 - * @param int $payments_made Number of payments made.
411 - * @param int $max_payments Maximum number of payments.
412 - */
413 - private function add_payment_milestone_notes( $subscription_id, $payments_made, $max_payments ) {
414 - if ( ! $max_payments || $max_payments <= 0 ) {
415 - return;
416 - }
417 -
418 - $percentage = round( ( $payments_made / $max_payments ) * 100 );
419 - $milestone_key = '_subscrpt_milestone_' . $percentage . '_logged';
420 -
421 - // Check if this milestone has already been logged
422 - if ( get_post_meta( $subscription_id, $milestone_key, true ) ) {
423 - return;
424 - }
425 -
426 - $milestone_note = '';
427 - $activity_type = '';
428 -
429 - switch ( $percentage ) {
430 - case 25:
431 - $milestone_note = sprintf(
432 - /* translators: %1$d: payments made, %2$d: total payments */
433 - __( 'Payment milestone reached: %1$d of %2$d payments completed (25%%).', 'subscription' ),
434 - $payments_made,
435 - $max_payments
436 - );
437 - $activity_type = __( 'Payment Milestone - 25%', 'subscription' );
438 - break;
439 -
440 - case 50:
441 - $milestone_note = sprintf(
442 - /* translators: %1$d: payments made, %2$d: total payments */
443 - __( 'Payment milestone reached: %1$d of %2$d payments completed (50%%). Halfway there!', 'subscription' ),
444 - $payments_made,
445 - $max_payments
446 - );
447 - $activity_type = __( 'Payment Milestone - 50%', 'subscription' );
448 - break;
449 -
450 - case 75:
451 - $milestone_note = sprintf(
452 - /* translators: %1$d: payments made, %2$d: total payments */
453 - __( 'Payment milestone reached: %1$d of %2$d payments completed (75%%). Almost complete!', 'subscription' ),
454 - $payments_made,
455 - $max_payments
456 - );
457 - $activity_type = __( 'Payment Milestone - 75%', 'subscription' );
458 - break;
459 -
460 - case 100:
461 - $milestone_note = sprintf(
462 - /* translators: %1$d: payments made, %2$d: total payments */
463 - __( 'Payment milestone reached: %1$d of %2$d payments completed (100%%). Split payment plan complete!', 'subscription' ),
464 - $payments_made,
465 - $max_payments
466 - );
467 - $activity_type = __( 'Payment Milestone - 100%', 'subscription' );
468 - break;
469 - }
470 -
471 - // Add milestone note if applicable
472 - if ( $milestone_note ) {
473 - $comment_id = wp_insert_comment(
474 - array(
475 - 'comment_author' => 'Subscription for WooCommerce',
476 - 'comment_content' => $milestone_note,
477 - 'comment_post_ID' => $subscription_id,
478 - 'comment_type' => 'order_note',
479 - )
480 - );
481 - update_comment_meta( $comment_id, '_subscrpt_activity', $activity_type );
482 - update_comment_meta( $comment_id, '_subscrpt_activity_type', 'split_payment' );
483 -
484 - // Mark milestone as logged
485 - update_post_meta( $subscription_id, $milestone_key, current_time( 'timestamp' ) );
486 433 }
487 434 }
488 435
489 436 /**