PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 1.9.5
Subscriptions for WooCommerce with Stripe Recurring Payments v1.9.5
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 / Action.php

Action.php in Subscriptions for WooCommerce with Stripe Recurring Payments 1.9.5, at includes/Illuminate/Action.php

173 lines 5.1 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 * Action [ helper class ]
7 *
8 * @package SpringDevs\Subscription\Illuminate
9 */
10 class Action {
11
12 /**
13 * Did when status changes.
14 *
15 * @param string $status Status.
16 * @param int $subscription_id Subscription ID.
17 * @param bool $write_comment Write comment?.
18 */
19 public static function status( string $status, int $subscription_id, bool $write_comment = true ) {
20 $old_status = get_post_status( $subscription_id );
21
22 wp_update_post(
23 array(
24 'ID' => $subscription_id,
25 'post_status' => $status,
26 )
27 );
28
29 if ( $write_comment ) {
30 self::write_comment( $status, $subscription_id );
31 }
32
33 // Trigger status change action
34 do_action( 'subscrpt_subscription_status_changed', $subscription_id, $old_status, $status );
35
36 // Trigger resumption event if subscription is being activated from cancelled or pending cancellation
37 if ( $status === 'active' && in_array( $old_status, array( 'cancelled', 'pe_cancelled' ) ) ) {
38 do_action( 'subscrpt_subscription_resumed', $subscription_id, $old_status );
39 }
40 }
41
42 /**
43 * Write Comment based on status.
44 *
45 * @param string $status Status.
46 * @param Int $subscription_id Subscription ID.
47 */
48 public static function write_comment( string $status, int $subscription_id ) {
49 switch ( $status ) {
50 case 'expired':
51 self::expired( $subscription_id );
52 break;
53 case 'active':
54 self::active( $subscription_id );
55 break;
56 case 'pending':
57 self::pending( $subscription_id );
58 break;
59 case 'cancelled':
60 self::cancelled( $subscription_id );
61 break;
62 case 'pe_cancelled':
63 self::pe_cancelled( $subscription_id );
64 break;
65 }
66 }
67
68 /**
69 * Write Comment About expired Subscription.
70 *
71 * @param int $subscription_id Subscription ID.
72 */
73 private static function expired( int $subscription_id ) {
74 $comment_id = wp_insert_comment(
75 array(
76 'comment_author' => 'Subscription for WooCommerce',
77 'comment_content' => 'Subscription is Expired',
78 'comment_post_ID' => $subscription_id,
79 'comment_type' => 'order_note',
80 )
81 );
82 update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Expired' );
83 update_comment_meta( $comment_id, '_subscrpt_activity_type', 'subs_expired' );
84
85 do_action( 'subscrpt_subscription_expired', $subscription_id );
86 }
87
88 /**
89 * Write Comment About Active Subscription.
90 *
91 * @param int $subscription_id Subscription ID.
92 */
93 private static function active( int $subscription_id ) {
94 $comment_id = wp_insert_comment(
95 array(
96 'comment_author' => 'Subscription for WooCommerce',
97 'comment_content' => 'Subscription activated.Next payment due date set.',
98 'comment_post_ID' => $subscription_id,
99 'comment_type' => 'order_note',
100 )
101 );
102 update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Activated' );
103 update_comment_meta( $comment_id, '_subscrpt_activity_type', 'subs_activated' );
104
105 do_action( 'subscrpt_subscription_activated', $subscription_id );
106 }
107
108 /**
109 * Write Comment About Subscription Pending.
110 *
111 * @param int $subscription_id Subscription ID.
112 */
113 private static function pending( int $subscription_id ) {
114 $comment_id = wp_insert_comment(
115 array(
116 'comment_author' => 'Subscription for WooCommerce',
117 'comment_content' => 'Subscription is pending.',
118 'comment_post_ID' => $subscription_id,
119 'comment_type' => 'order_note',
120 )
121 );
122 update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Pending' );
123 update_comment_meta( $comment_id, '_subscrpt_activity_type', 'subs_pending' );
124
125 do_action( 'subscrpt_subscription_pending', $subscription_id );
126 }
127
128 /**
129 * Write Comment About cancelled Subscription.
130 *
131 * @param int $subscription_id Subscription ID.
132 */
133 private static function cancelled( int $subscription_id ) {
134 $comment_id = wp_insert_comment(
135 array(
136 'comment_author' => 'Subscription for WooCommerce',
137 'comment_content' => 'Subscription is Cancelled.',
138 'comment_post_ID' => $subscription_id,
139 'comment_type' => 'order_note',
140 )
141 );
142 update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Cancelled' );
143 update_comment_meta( $comment_id, '_subscrpt_activity_type', 'subs_cancelled' );
144
145 WC()->mailer();
146 do_action( 'subscrpt_subscription_cancelled_email_notification', $subscription_id );
147 do_action( 'subscrpt_subscription_cancelled', $subscription_id );
148
149 // Fire split payment cancelled action
150 do_action( 'subscrpt_split_payment_cancelled', $subscription_id );
151 }
152
153 /**
154 * Write Comment About Pending Cancellation.
155 *
156 * @param int $subscription_id Subscription ID.
157 */
158 private static function pe_cancelled( int $subscription_id ) {
159 $comment_id = wp_insert_comment(
160 array(
161 'comment_author' => 'Subscription for WooCommerce',
162 'comment_content' => 'Subscription is Pending Cancellation.',
163 'comment_post_ID' => $subscription_id,
164 'comment_type' => 'order_note',
165 )
166 );
167 update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Pending Cancellation' );
168 update_comment_meta( $comment_id, '_subscrpt_activity_type', 'subs_pe_cancel' );
169
170 do_action( 'subscrpt_subscription_pending_cancellation', $subscription_id );
171 }
172 }
173