@@ -173,21 +173,42 @@ public static function should_send_notification() {
173
173
}
174
174
175
175
/**
176
- * Adds actions to the admin edit subscriptions page, if the subscription hasn't ended and the payment method supports them .
176
+ * Adds actions to the admin edit subscriptions page.
177
177
*
178
178
* @param array $actions An array of available actions
179
179
* @return array An array of updated actions
180
- * @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
181
180
*/
182
181
public static function add_notification_actions ( $ actions ) {
183
182
global $ theorder ;
184
183
185
184
if ( wcs_is_subscription ( $ theorder ) ) {
186
- //TODO maybe send only for active, on hold subscriptions?
187
- $ actions ['wcs_customer_notification_free_trial_expiration ' ] = esc_html__ ( 'Send Free Trial Expiration notification ' , 'woocommerce-subscriptions ' );
188
- $ actions ['wcs_customer_notification_subscription_expiration ' ] = esc_html__ ( 'Send Subscription Expiration notification ' , 'woocommerce-subscriptions ' );
189
- $ actions ['wcs_customer_notification_manual_renewal ' ] = esc_html__ ( 'Send Manual Renewal notification ' , 'woocommerce-subscriptions ' );
190
- $ actions ['wcs_customer_notification_auto_renewal ' ] = esc_html__ ( 'Send Automatic Renewal notification ' , 'woocommerce-subscriptions ' );
185
+ $ subscription = $ theorder ;
186
+ //TODO: confirm if these statuses make sense.
187
+ $ allowed_statuses = array (
188
+ 'active ' ,
189
+ 'on-hold ' ,
190
+ 'pending-cancellation ' ,
191
+ );
192
+
193
+ if ( ! in_array ( $ subscription ->get_status (), $ allowed_statuses , true ) ) {
194
+ return $ actions ;
195
+ }
196
+
197
+ if ( $ subscription ->get_date ( 'trial_end ' ) ) {
198
+ $ actions ['wcs_customer_notification_free_trial_expiration ' ] = esc_html__ ( 'Send Free Trial Expiration notification ' , 'woocommerce-subscriptions ' );
199
+ }
200
+
201
+ if ( $ subscription ->get_date ( 'end ' ) ) {
202
+ $ actions ['wcs_customer_notification_subscription_expiration ' ] = esc_html__ ( 'Send Subscription Expiration notification ' , 'woocommerce-subscriptions ' );
203
+ }
204
+
205
+ if ( $ subscription ->get_date ( 'next_payment ' ) ) {
206
+ if ( $ subscription ->is_manual () ) {
207
+ $ actions ['wcs_customer_notification_manual_renewal ' ] = esc_html__ ( 'Send Manual Renewal notification ' , 'woocommerce-subscriptions ' );
208
+ } else {
209
+ $ actions ['wcs_customer_notification_auto_renewal ' ] = esc_html__ ( 'Send Automatic Renewal notification ' , 'woocommerce-subscriptions ' );
210
+ }
211
+ }
191
212
}
192
213
193
214
return $ actions ;
0 commit comments