PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 1.3.0
Subscriptions for WooCommerce with Stripe Recurring Payments v1.3.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 1.4.1 1.4.2 1.5.0 1.5.1 All 61 releases
subscription / includes / Illuminate / Cron.php

Cron.php in Subscriptions for WooCommerce with Stripe Recurring Payments 1.3.0, at includes/Illuminate/Cron.php

49 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SpringDevs\Subscription\Illuminate;
4
5 /**
6 * Class Cron
7 *
8 * @package SpringDevs\Subscription\Illuminate
9 */
10 class Cron {
11
12 /**
13 * Initialize the class.
14 */
15 public function __construct() {
16 add_action( 'subscrpt_daily_cron', array( $this, 'daily_cron_task' ) );
17 }
18
19 /**
20 * Run daily cron task to check if subscription expired.
21 */
22 public function daily_cron_task() {
23 $args = array(
24 'post_type' => 'subscrpt_order',
25 'post_status' => array( 'active', 'pe_cancelled' ),
26 'fields' => 'ids',
27 'author' => get_current_user_id(),
28 );
29
30 $active_subscriptions = get_posts( $args );
31
32 if ( $active_subscriptions && count( $active_subscriptions ) > 0 ) {
33 foreach ( $active_subscriptions as $subscription ) {
34 $start_date = get_post_meta( $subscription, '_subscrpt_start_date', true );
35 $next_date = get_post_meta( $subscription, '_subscrpt_next_date', true );
36 $trial = get_post_meta( $subscription, '_subscrpt_trial', true );
37
38 if ( time() >= $next_date || ( null !== $trial && time() >= $start_date ) ) {
39 if ( 'pe_cancelled' === get_post_status( $subscription ) ) {
40 Action::status( 'cancelled', $subscription );
41 } else {
42 Action::status( 'expired', $subscription );
43 }
44 }
45 }
46 }
47 }
48 }
49