| @@ -12,13 +12,13 @@ | ||
| 12 | 12 | /** |
| 13 | 13 | * Initialize the class. |
| 14 | 14 | */ |
| 15 | 15 | public function __construct() { |
| 16 | - add_action( 'subscrpt_hourly_cron', array( $this, 'hourly_cron_task' ) ); | |
| 16 | + add_action( 'subscrpt_hourly_cron', [ $this, 'hourly_cron_task' ] ); | |
| 17 | 17 | |
| 18 | 18 | // ? Dev Note: This is a backward compatibility measure. Remove following action and maybe_reschedule_cron() method after 1 Jan, 2027. |
| 19 | 19 | // Safety net: if the old WP-Cron event fires before migration clears it, still process subscriptions. |
| 20 | - add_action( 'subscrpt_daily_cron', array( $this, 'hourly_cron_task' ) ); | |
| 20 | + add_action( 'subscrpt_daily_cron', [ $this, 'hourly_cron_task' ] ); | |
| 21 | 21 | $this->maybe_reschedule_cron(); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
| @@ -60,37 +60,40 @@ | ||
| 60 | 60 | do_action( 'after_subscription_update_cron' ); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | - * Update subscription statuses. | |
| 64 | + * Expire active subscriptions whose term has ended. | |
| 65 | + * | |
| 66 | + * Pending cancellations (`pe_cancelled`) are handled separately by | |
| 67 | + * {@see Cancellation}, not here. | |
| 65 | 68 | */ |
| 66 | 69 | public function update_subscription_statusses() { |
| 67 | - $args = array( | |
| 70 | + $args = [ | |
| 68 | 71 | 'post_type' => 'subscrpt_order', |
| 69 | - 'post_status' => array( 'active', 'pe_cancelled' ), | |
| 72 | + 'post_status' => [ 'active' ], | |
| 70 | 73 | 'fields' => 'ids', |
| 71 | - 'meta_query' => array( | |
| 74 | + 'meta_query' => [ | |
| 72 | 75 | 'relation' => 'OR', |
| 73 | - array( | |
| 76 | + [ | |
| 74 | 77 | 'key' => '_subscrpt_next_date', |
| 75 | 78 | 'value' => time(), |
| 76 | 79 | 'compare' => '<=', |
| 77 | - ), | |
| 78 | - array( | |
| 80 | + ], | |
| 81 | + [ | |
| 79 | 82 | 'relation' => 'AND', |
| 80 | - array( | |
| 83 | + [ | |
| 81 | 84 | 'key' => '_subscrpt_trial', |
| 82 | 85 | 'value' => null, |
| 83 | 86 | 'compare' => '!=', |
| 84 | - ), | |
| 85 | - array( | |
| 87 | + ], | |
| 88 | + [ | |
| 86 | 89 | 'key' => '_subscrpt_start_date', |
| 87 | 90 | 'value' => time(), |
| 88 | 91 | 'compare' => '<=', |
| 89 | - ), | |
| 90 | - ), | |
| 91 | - ), | |
| 92 | - ); | |
| 92 | + ], | |
| 93 | + ], | |
| 94 | + ], | |
| 95 | + ]; | |
| 93 | 96 | |
| 94 | 97 | $expired_subscriptions = get_posts( $args ); |
| 95 | 98 | |
| 96 | 99 | if ( $expired_subscriptions && count( $expired_subscriptions ) > 0 ) { |
| @@ -96,13 +99,9 @@ | ||
| 96 | 99 | if ( $expired_subscriptions && count( $expired_subscriptions ) > 0 ) { |
| 97 | 100 | // Initialize WooCommerce mailer before processing |
| 98 | 101 | if ( function_exists( 'WC' ) && WC()->mailer() ) { |
| 99 | 102 | foreach ( $expired_subscriptions as $subscription ) { |
| 100 | - if ( 'pe_cancelled' === get_post_status( $subscription ) ) { | |
| 101 | - Action::status( 'cancelled', $subscription ); | |
| 102 | - } else { | |
| 103 | - Action::status( 'expired', $subscription ); | |
| 104 | - } | |
| 103 | + Action::status( 'expired', $subscription ); | |
| 105 | 104 | } |
| 106 | 105 | } |
| 107 | 106 | } |
| 108 | 107 | } |