PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 1.3.1
Subscriptions for WooCommerce with Stripe Recurring Payments v1.3.1
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 / AutoRenewal.php

AutoRenewal.php in Subscriptions for WooCommerce with Stripe Recurring Payments 1.3.1, at includes/Illuminate/AutoRenewal.php

89 lines 2.4 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 AutoRenewal
7 *
8 * @package SpringDevs\Subscription\Illuminate
9 */
10 class AutoRenewal {
11
12 /**
13 * Initialize the class
14 */
15 public function __construct() {
16 add_action( 'subscrpt_subscription_expired', array( $this, 'after_subscription_expired' ) );
17 add_filter(
18 'subscrpt_renewal_item_meta',
19 function ( $item_meta, $product ) {
20 if ( 'updated' !== get_option( 'subscrpt_renewal_price', 'subscribed' ) || ! $product ) {
21 return $item_meta;
22 }
23 if ( $product->is_type( 'variable' ) ) {
24 $product = wc_get_product( $product->get_meta( '_subscrpt_convertation_default_variation_for_renewal', true ) );
25 if ( ! $product ) {
26 return $item_meta;
27 }
28 }
29
30 $timing_per = $product->get_meta( '_subscrpt_timing_per' );
31 $timing_option = $product->get_meta( '_subscrpt_timing_option' );
32
33 return array(
34 'time' => empty( $timing_per ) ? 1 : $timing_per,
35 'type' => $timing_option,
36 'trial' => null,
37 );
38 },
39 10,
40 2
41 );
42 add_filter(
43 'subscrpt_renewal_product_args',
44 function ( $product_args, $product, $order_item ) {
45 if ( 'updated' !== get_option( 'subscrpt_renewal_price', 'subscribed' ) ) {
46 return $product_args;
47 }
48
49 if ( ! $product ) {
50 if ( ! is_admin() ) {
51 wc_add_notice( __( 'Subscription early renewal order creation failed due to product deletion !', 'sdevs_subscrpt' ), 'error' );
52 }
53 return false;
54 }
55
56 if ( $product->is_type( 'variable' ) ) {
57 $product = wc_get_product( $product->get_meta( '_subscrpt_convertation_default_variation_for_renewal', true ) );
58 if ( ! $product ) {
59 if ( ! is_admin() ) {
60 wc_add_notice( __( 'Subscription early renewal order creation failed due to product deletion !', 'sdevs_subscrpt' ), 'error' );
61 }
62 return false;
63 }
64 }
65 $product_args = array(
66 'name' => $product->get_name(),
67 'subtotal' => $product->get_price() * $order_item->get_quantity(),
68 'total' => $product->get_price() * $order_item->get_quantity(),
69 );
70
71 return $product_args;
72 },
73 10,
74 3
75 );
76 }
77
78 /**
79 * After Expired Subscription.
80 *
81 * @param int $subscription_id Subscription ID.
82 */
83 public function after_subscription_expired( $subscription_id ) {
84 if ( subscrpt_is_auto_renew_enabled() ) {
85 Helper::create_renewal_order( $subscription_id );
86 }
87 }
88 }
89