Completed
Push — master ( d6f625...0d8432 )
by Sébastien
01:23
created
includes/class-wcsatt-stt-display.php 1 patch
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -8,163 +8,163 @@
 block discarded – undo
8 8
 
9 9
 class WCSATT_STT_Display extends WCS_ATT_Display {
10 10
 
11
-	/**
12
-	 * Initialize the display.
13
-	 *
14
-	 * @access public
15
-	 * @static
16
-	 */
17
-	public static function init() {
18
-		// Adds the sign up fee and trial data to the price html on the 'wcsatt_overridden_subscription_prices_product' filter.
19
-		add_filter( 'wcsatt_overridden_subscription_prices_product', __CLASS__ . '::add_sub_scheme_data_price_html', 10, 3 );
20
-
21
-		// Adds the extra subscription scheme data to the product object on the 'wcsatt_converted_product_for_scheme_option' filter.
22
-		add_filter( 'wcsatt_converted_product_for_scheme_option', __CLASS__ . '::sub_product_scheme_option', 10, 2 );
23
-
24
-		// Filters the price string to include the sign up fee and/or trial to pass per scheme option on the 'wcsatt_single_product_subscription_scheme_price_html' filter.
25
-		add_filter( 'wcsatt_single_product_subscription_scheme_price_html', __CLASS__ . '::get_price_string', 10, 2 );
26
-
27
-		// Filters the lowest price string to include the sign up fee on the 'wcsatt_get_single_product_lowest_price_string' filter.
28
-		add_filter( 'wcsatt_get_single_product_lowest_price_string', __CLASS__ . '::get_lowest_price_string', 10, 2 );
29
-
30
-		// Filters the lowest price subscription scheme data on the 'wcsatt_get_lowest_price_sub_scheme_data' filter.
31
-		add_filter( 'wcsatt_get_lowest_price_sub_scheme_data', __CLASS__ . '::get_lowest_price_sub_scheme_data', 10, 2 );
32
-
33
-		// Adds the sign-up and/or trial data to the subscription scheme prices on the 'wcsatt_subscription_scheme_prices' filter.
34
-		add_filter( 'wcsatt_subscription_scheme_prices', __CLASS__ . '::add_subscription_scheme_prices', 10, 2 );
35
-	}
36
-
37
-	/**
38
-	 * Adds the additional subscription scheme data for products with attached subscription schemes.
39
-	 *
40
-	 * @access public
41
-	 * @static
42
-	 * @param  object     $_product
43
-	 * @param  array      $subscription_scheme
44
-	 * @param  WC_Product $product
45
-	 * @return string
46
-	 */
47
-	public static function add_sub_scheme_data_price_html( $_product, $subscription_scheme, $product ) {
48
-		if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) ) {
49
-			$_product->subscription_sign_up_fee = $subscription_scheme[ 'subscription_sign_up_fee' ];
50
-		}
51
-
52
-		if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) ) {
53
-			$_product->subscription_trial_length = $subscription_scheme[ 'subscription_trial_length' ];
54
-		}
55
-
56
-		if ( isset( $subscription_scheme[ 'subscription_trial_period' ] ) ) {
57
-			$_product->subscription_trial_period = $subscription_scheme[ 'subscription_trial_period' ];
58
-		}
59
-
60
-		return $_product;
61
-	} // END add_sub_scheme_data_price_html()
62
-
63
-	/**
64
-	 * Adds the extra subscription scheme data to the product object.
65
-	 * This allows the subscription price to change the initial and
66
-	 * recurring subscriptions.
67
-	 *
68
-	 * @access public
69
-	 * @static
70
-	 * @param  object $_cloned
71
-	 * @param  array  $subscription_scheme
72
-	 * @return object
73
-	 */
74
-	public static function sub_product_scheme_option( $_cloned, $subscription_scheme ) {
75
-		if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) && $subscription_scheme[ 'subscription_sign_up_fee' ] > 0 ) {
76
-			$_cloned->subscription_sign_up_fee = $subscription_scheme[ 'subscription_sign_up_fee' ];
77
-		}
78
-
79
-		if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) && 0 != $subscription_scheme[ 'subscription_trial_length' ] ) {
80
-			$_cloned->subscription_trial_length = $subscription_scheme[ 'subscription_trial_length' ];
81
-			$_cloned->subscription_trial_period = $subscription_scheme[ 'subscription_trial_period' ];
82
-		}
83
-
84
-		return $_cloned;
85
-	} // END sub_product_scheme_option()
86
-
87
-	/**
88
-	 * Filters the price string to include the sign up fee and/or trial 
89
-	 * to pass per subscription scheme option.
90
-	 *
91
-	 * @access public
92
-	 * @static
93
-	 * @param  array $prices
94
-	 * @param  array $subscription_scheme
95
-	 * @return array
96
-	 */
97
-	public static function get_price_string( $prices, $subscription_scheme ) {
98
-		if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) && $subscription_scheme[ 'subscription_sign_up_fee' ] > 0 ) {
99
-			$prices[ 'sign_up_fee' ] = $subscription_scheme[ 'subscription_sign_up_fee' ];
100
-		}
101
-
102
-		if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) && 0 != $subscription_scheme[ 'subscription_trial_length' ] ) {
103
-			$prices[ 'trial_length' ] = true;
104
-		}
105
-
106
-		return $prices;
107
-	} // END get_price_string()
108
-
109
-	/**
110
-	 * Filters the price string to include the sign up 
111
-	 * fee on the lowest subscription scheme.
112
-	 *
113
-	 * @access public
114
-	 * @static
115
-	 * @param  array $prices
116
-	 * @param  array $lowest_subscription_scheme
117
-	 * @return array
118
-	 */
119
-	public static function get_lowest_price_string( $prices,  $lowest_subscription_scheme ) {
120
-		if ( isset( $lowest_subscription_scheme[ 'sign_up_fee' ] ) && $lowest_subscription_scheme[ 'sign_up_fee' ] > 0 ) {
121
-			$prices[ 'sign_up_fee' ] = $lowest_subscription_scheme[ 'sign_up_fee' ];
122
-		}
123
-
124
-		return $prices;
125
-	} // END get_lowest_price_string()
126
-
127
-	/**
128
-	 * Adds the sign-up fee to the lowest subscription scheme option.
129
-	 *
130
-	 * @access public
131
-	 * @static
132
-	 * @param array $data
133
-	 * @param array $lowest_scheme
134
-	 * @return array
135
-	 */
136
-	public static function get_lowest_price_sub_scheme_data( $data, $lowest_scheme ) {
137
-		if ( isset( $lowest_scheme['subscription_sign_up_fee'] ) && $lowest_scheme['subscription_sign_up_fee'] > 0 ) {
138
-			$data['sign_up_fee'] = $lowest_scheme['subscription_sign_up_fee'];
139
-		}
140
-
141
-		return $data;
142
-	} // END get_lowest_price_sub_scheme_data()
143
-
144
-	/**
145
-	 * Adds the sign-up and/or trial data to the subscription scheme prices.
146
-	 *
147
-	 * @access public
148
-	 * @static
149
-	 * @param  array $prices
150
-	 * @param  array $subscription_scheme
151
-	 * @return array
152
-	 */
153
-	public static function add_subscription_scheme_prices( $prices, $subscription_scheme ) {
154
-		if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) ) {
155
-			$prices[ 'sign_up_fee' ] = $subscription_scheme[ 'subscription_sign_up_fee' ];
156
-		}
157
-
158
-		if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) ) {
159
-			$prices[ 'trial_length' ] = $subscription_scheme[ 'subscription_trial_length' ];
160
-		}
161
-
162
-		if ( isset( $subscription_scheme[ 'subscription_trial_period' ] ) ) {
163
-			$prices[ 'trial_period' ] = $subscription_scheme[ 'subscription_trial_period' ];
164
-		}
165
-
166
-		return $prices;
167
-	} // END add_subscription_scheme_prices()
11
+    /**
12
+     * Initialize the display.
13
+     *
14
+     * @access public
15
+     * @static
16
+     */
17
+    public static function init() {
18
+        // Adds the sign up fee and trial data to the price html on the 'wcsatt_overridden_subscription_prices_product' filter.
19
+        add_filter( 'wcsatt_overridden_subscription_prices_product', __CLASS__ . '::add_sub_scheme_data_price_html', 10, 3 );
20
+
21
+        // Adds the extra subscription scheme data to the product object on the 'wcsatt_converted_product_for_scheme_option' filter.
22
+        add_filter( 'wcsatt_converted_product_for_scheme_option', __CLASS__ . '::sub_product_scheme_option', 10, 2 );
23
+
24
+        // Filters the price string to include the sign up fee and/or trial to pass per scheme option on the 'wcsatt_single_product_subscription_scheme_price_html' filter.
25
+        add_filter( 'wcsatt_single_product_subscription_scheme_price_html', __CLASS__ . '::get_price_string', 10, 2 );
26
+
27
+        // Filters the lowest price string to include the sign up fee on the 'wcsatt_get_single_product_lowest_price_string' filter.
28
+        add_filter( 'wcsatt_get_single_product_lowest_price_string', __CLASS__ . '::get_lowest_price_string', 10, 2 );
29
+
30
+        // Filters the lowest price subscription scheme data on the 'wcsatt_get_lowest_price_sub_scheme_data' filter.
31
+        add_filter( 'wcsatt_get_lowest_price_sub_scheme_data', __CLASS__ . '::get_lowest_price_sub_scheme_data', 10, 2 );
32
+
33
+        // Adds the sign-up and/or trial data to the subscription scheme prices on the 'wcsatt_subscription_scheme_prices' filter.
34
+        add_filter( 'wcsatt_subscription_scheme_prices', __CLASS__ . '::add_subscription_scheme_prices', 10, 2 );
35
+    }
36
+
37
+    /**
38
+     * Adds the additional subscription scheme data for products with attached subscription schemes.
39
+     *
40
+     * @access public
41
+     * @static
42
+     * @param  object     $_product
43
+     * @param  array      $subscription_scheme
44
+     * @param  WC_Product $product
45
+     * @return string
46
+     */
47
+    public static function add_sub_scheme_data_price_html( $_product, $subscription_scheme, $product ) {
48
+        if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) ) {
49
+            $_product->subscription_sign_up_fee = $subscription_scheme[ 'subscription_sign_up_fee' ];
50
+        }
51
+
52
+        if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) ) {
53
+            $_product->subscription_trial_length = $subscription_scheme[ 'subscription_trial_length' ];
54
+        }
55
+
56
+        if ( isset( $subscription_scheme[ 'subscription_trial_period' ] ) ) {
57
+            $_product->subscription_trial_period = $subscription_scheme[ 'subscription_trial_period' ];
58
+        }
59
+
60
+        return $_product;
61
+    } // END add_sub_scheme_data_price_html()
62
+
63
+    /**
64
+     * Adds the extra subscription scheme data to the product object.
65
+     * This allows the subscription price to change the initial and
66
+     * recurring subscriptions.
67
+     *
68
+     * @access public
69
+     * @static
70
+     * @param  object $_cloned
71
+     * @param  array  $subscription_scheme
72
+     * @return object
73
+     */
74
+    public static function sub_product_scheme_option( $_cloned, $subscription_scheme ) {
75
+        if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) && $subscription_scheme[ 'subscription_sign_up_fee' ] > 0 ) {
76
+            $_cloned->subscription_sign_up_fee = $subscription_scheme[ 'subscription_sign_up_fee' ];
77
+        }
78
+
79
+        if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) && 0 != $subscription_scheme[ 'subscription_trial_length' ] ) {
80
+            $_cloned->subscription_trial_length = $subscription_scheme[ 'subscription_trial_length' ];
81
+            $_cloned->subscription_trial_period = $subscription_scheme[ 'subscription_trial_period' ];
82
+        }
83
+
84
+        return $_cloned;
85
+    } // END sub_product_scheme_option()
86
+
87
+    /**
88
+     * Filters the price string to include the sign up fee and/or trial 
89
+     * to pass per subscription scheme option.
90
+     *
91
+     * @access public
92
+     * @static
93
+     * @param  array $prices
94
+     * @param  array $subscription_scheme
95
+     * @return array
96
+     */
97
+    public static function get_price_string( $prices, $subscription_scheme ) {
98
+        if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) && $subscription_scheme[ 'subscription_sign_up_fee' ] > 0 ) {
99
+            $prices[ 'sign_up_fee' ] = $subscription_scheme[ 'subscription_sign_up_fee' ];
100
+        }
101
+
102
+        if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) && 0 != $subscription_scheme[ 'subscription_trial_length' ] ) {
103
+            $prices[ 'trial_length' ] = true;
104
+        }
105
+
106
+        return $prices;
107
+    } // END get_price_string()
108
+
109
+    /**
110
+     * Filters the price string to include the sign up 
111
+     * fee on the lowest subscription scheme.
112
+     *
113
+     * @access public
114
+     * @static
115
+     * @param  array $prices
116
+     * @param  array $lowest_subscription_scheme
117
+     * @return array
118
+     */
119
+    public static function get_lowest_price_string( $prices,  $lowest_subscription_scheme ) {
120
+        if ( isset( $lowest_subscription_scheme[ 'sign_up_fee' ] ) && $lowest_subscription_scheme[ 'sign_up_fee' ] > 0 ) {
121
+            $prices[ 'sign_up_fee' ] = $lowest_subscription_scheme[ 'sign_up_fee' ];
122
+        }
123
+
124
+        return $prices;
125
+    } // END get_lowest_price_string()
126
+
127
+    /**
128
+     * Adds the sign-up fee to the lowest subscription scheme option.
129
+     *
130
+     * @access public
131
+     * @static
132
+     * @param array $data
133
+     * @param array $lowest_scheme
134
+     * @return array
135
+     */
136
+    public static function get_lowest_price_sub_scheme_data( $data, $lowest_scheme ) {
137
+        if ( isset( $lowest_scheme['subscription_sign_up_fee'] ) && $lowest_scheme['subscription_sign_up_fee'] > 0 ) {
138
+            $data['sign_up_fee'] = $lowest_scheme['subscription_sign_up_fee'];
139
+        }
140
+
141
+        return $data;
142
+    } // END get_lowest_price_sub_scheme_data()
143
+
144
+    /**
145
+     * Adds the sign-up and/or trial data to the subscription scheme prices.
146
+     *
147
+     * @access public
148
+     * @static
149
+     * @param  array $prices
150
+     * @param  array $subscription_scheme
151
+     * @return array
152
+     */
153
+    public static function add_subscription_scheme_prices( $prices, $subscription_scheme ) {
154
+        if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) ) {
155
+            $prices[ 'sign_up_fee' ] = $subscription_scheme[ 'subscription_sign_up_fee' ];
156
+        }
157
+
158
+        if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) ) {
159
+            $prices[ 'trial_length' ] = $subscription_scheme[ 'subscription_trial_length' ];
160
+        }
161
+
162
+        if ( isset( $subscription_scheme[ 'subscription_trial_period' ] ) ) {
163
+            $prices[ 'trial_period' ] = $subscription_scheme[ 'subscription_trial_period' ];
164
+        }
165
+
166
+        return $prices;
167
+    } // END add_subscription_scheme_prices()
168 168
 
169 169
 }
170 170
 
Please login to merge, or discard this patch.
includes/class-wcsatt-stt-cart.php 1 patch
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -8,69 +8,69 @@
 block discarded – undo
8 8
 
9 9
 class WCSATT_STT_Cart extends WCS_ATT_Cart {
10 10
 
11
-	/**
12
-	 * Initialize the cart.
13
-	 *
14
-	 * @access public
15
-	 * @static
16
-	 */
17
-	public static function init() {
18
-		// Overrides the price of the subscription for sign up fee and/or trial on the 'wcsatt_cart_item' filter.
19
-		add_filter( 'wcsatt_cart_item', __CLASS__ . '::update_cart_item_sub_data', 10, 1 );
20
-	}
21
-
22
-	/**
23
-	 * Updates the cart item data for a subscription product that
24
-	 * has a sign-up fee and/or trial period applied.
25
-	 *
26
-	 * @access public
27
-	 * @static
28
-	 * @param  array $cart_item
29
-	 * @return array
30
-	 */
31
-	public static function update_cart_item_sub_data( $cart_item ) {
32
-		$active_scheme = WCS_ATT_Schemes::get_active_subscription_scheme( $cart_item );
33
-
34
-		$subscription_prices = WCS_ATT_Scheme_Prices::get_active_subscription_scheme_prices( $cart_item, $active_scheme );
35
-
36
-		if ( $active_scheme && $cart_item['data']->is_converted_to_sub == 'yes' ) {
37
-
38
-			// Subscription Price
39
-			$price = $cart_item['data']->subscription_price;
40
-
41
-			// Is there a sign up fee?
42
-			$sign_up_fee = isset( $subscription_prices['sign_up_fee'] ) ? $subscription_prices['sign_up_fee'] : '';
43
-
44
-			// Checks if the cart item is a supported bundle type child.
45
-			$container_key = WCS_ATT_Integrations::has_bundle_type_container( $cart_item );
46
-
47
-			// If the cart item is a child item then reset the sign-up fee.
48
-			if ( false !== $container_key ) { $sign_up_fee = ''; }
49
-
50
-			// Put both the subscription price and the sign-up fee together.
51
-			$new_price = round( $price + $sign_up_fee, wc_get_price_decimals() );
52
-
53
-			if ( $sign_up_fee > 0 ) {
54
-				$cart_item['data']->initial_amount = $new_price;
55
-				$cart_item['data']->subscription_sign_up_fee = $sign_up_fee;
56
-			}
57
-
58
-			$trial_length = isset( $subscription_prices['trial_length'] ) ? $subscription_prices['trial_length'] : 0;
59
-			$trial_period = isset( $subscription_prices['trial_period'] ) ? $subscription_prices['trial_period'] : '';
60
-
61
-			// If a trial length is more than zero then set the conditions for the cart.
62
-			if ( $trial_length > 0 ) {
63
-				$cart_item['data']->subscription_trial_length = $trial_length;
64
-				$cart_item['data']->subscription_trial_period = $trial_period;
65
-			} else {
66
-				$cart_item['data']->subscription_trial_length = 0;
67
-				$cart_item['data']->subscription_trial_period = '';
68
-			}
69
-
70
-		}
71
-
72
-		return $cart_item;
73
-	} // END update_cart_item_sub_data()
11
+    /**
12
+     * Initialize the cart.
13
+     *
14
+     * @access public
15
+     * @static
16
+     */
17
+    public static function init() {
18
+        // Overrides the price of the subscription for sign up fee and/or trial on the 'wcsatt_cart_item' filter.
19
+        add_filter( 'wcsatt_cart_item', __CLASS__ . '::update_cart_item_sub_data', 10, 1 );
20
+    }
21
+
22
+    /**
23
+     * Updates the cart item data for a subscription product that
24
+     * has a sign-up fee and/or trial period applied.
25
+     *
26
+     * @access public
27
+     * @static
28
+     * @param  array $cart_item
29
+     * @return array
30
+     */
31
+    public static function update_cart_item_sub_data( $cart_item ) {
32
+        $active_scheme = WCS_ATT_Schemes::get_active_subscription_scheme( $cart_item );
33
+
34
+        $subscription_prices = WCS_ATT_Scheme_Prices::get_active_subscription_scheme_prices( $cart_item, $active_scheme );
35
+
36
+        if ( $active_scheme && $cart_item['data']->is_converted_to_sub == 'yes' ) {
37
+
38
+            // Subscription Price
39
+            $price = $cart_item['data']->subscription_price;
40
+
41
+            // Is there a sign up fee?
42
+            $sign_up_fee = isset( $subscription_prices['sign_up_fee'] ) ? $subscription_prices['sign_up_fee'] : '';
43
+
44
+            // Checks if the cart item is a supported bundle type child.
45
+            $container_key = WCS_ATT_Integrations::has_bundle_type_container( $cart_item );
46
+
47
+            // If the cart item is a child item then reset the sign-up fee.
48
+            if ( false !== $container_key ) { $sign_up_fee = ''; }
49
+
50
+            // Put both the subscription price and the sign-up fee together.
51
+            $new_price = round( $price + $sign_up_fee, wc_get_price_decimals() );
52
+
53
+            if ( $sign_up_fee > 0 ) {
54
+                $cart_item['data']->initial_amount = $new_price;
55
+                $cart_item['data']->subscription_sign_up_fee = $sign_up_fee;
56
+            }
57
+
58
+            $trial_length = isset( $subscription_prices['trial_length'] ) ? $subscription_prices['trial_length'] : 0;
59
+            $trial_period = isset( $subscription_prices['trial_period'] ) ? $subscription_prices['trial_period'] : '';
60
+
61
+            // If a trial length is more than zero then set the conditions for the cart.
62
+            if ( $trial_length > 0 ) {
63
+                $cart_item['data']->subscription_trial_length = $trial_length;
64
+                $cart_item['data']->subscription_trial_period = $trial_period;
65
+            } else {
66
+                $cart_item['data']->subscription_trial_length = 0;
67
+                $cart_item['data']->subscription_trial_period = '';
68
+            }
69
+
70
+        }
71
+
72
+        return $cart_item;
73
+    } // END update_cart_item_sub_data()
74 74
 
75 75
 }
76 76
 
Please login to merge, or discard this patch.
includes/admin/class-wcsatt-stt-admin.php 1 patch
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -8,178 +8,178 @@
 block discarded – undo
8 8
 
9 9
 class WCSATT_STT_Admin extends WCS_ATT_Admin {
10 10
 
11
-	/**
12
-	 * Initialize the product meta.
13
-	 *
14
-	 * @access public
15
-	 * @static
16
-	 */
17
-	public static function init() {
18
-		// Admin scripts and styles.
19
-		add_action( 'admin_enqueue_scripts', __CLASS__ . '::admin_style' );
20
-
21
-		// Adds to the default values for subscriptions schemes content.
22
-		add_filter( 'wcsatt_default_subscription_scheme', __CLASS__ . '::subscription_schemes_content', 10, 1 );
23
-
24
-		// Subscription scheme options displayed on the 'wcsatt_subscription_scheme_product_content' action.
25
-		add_action( 'wcsatt_subscription_scheme_product_content', __CLASS__ . '::wcsatt_stt_fields', 15, 3 );
26
-
27
-		// Filter the subscription scheme data to process the sign up and trial options on the ''wcsatt_subscription_scheme_process_scheme_data' filter.
28
-		add_filter( 'wcsatt_subscription_scheme_process_scheme_data', __CLASS__ . '::wcsatt_stt_process_scheme_data', 10, 2 );
29
-	}
30
-
31
-	/**
32
-	 * Load style.
33
-	 *
34
-	 * @return void
35
-	 */
36
-	public static function admin_style() {
37
-		// Get admin screen id.
38
-		$screen    = get_current_screen();
39
-		$screen_id = $screen ? $screen->id : '';
40
-
41
-		if ( in_array( $screen_id, array( 'edit-product', 'product' ) ) ) {
42
-			wp_register_style( 'wcsatt_stt_writepanel', WCSATT_STT::plugin_url() . '/assets/css/wcsatt-stt-write-panel.css', array( 'woocommerce_admin_styles' ), WCSATT_STT::VERSION );
43
-			wp_enqueue_style( 'wcsatt_stt_writepanel' );
44
-		}
45
-
46
-	} // END admin_style()
47
-
48
-	/**
49
-	 * Adds the default values for subscriptions schemes content.
50
-	 *
51
-	 * @access public
52
-	 * @static
53
-	 * @param  array $defaults
54
-	 * @return void
55
-	 */
56
-	public static function subscription_schemes_content( $defaults ) {
57
-		$new_defaults = array(
58
-			'subscription_sign_up_fee'  => '',
59
-			'subscription_trial_length' => '',
60
-			'subscription_trial_period' => ''
61
-		);
62
-
63
-		return array_merge( $new_defaults, $defaults );
64
-	} // END subscription_schemes_content()
65
-
66
-	/**
67
-	 * Adds the trial and sign up fields under the subscription section.
68
-	 *
69
-	 * @access public
70
-	 * @static
71
-	 * @param  int   $index
72
-	 * @param  array $scheme_data
73
-	 * @param  int   $post_id
74
-	 * @return void
75
-	 */
76
-	public static function wcsatt_stt_fields( $index, $scheme_data, $post_id ) {
77
-		if ( ! empty( $scheme_data ) ) {
78
-			$subscription_sign_up_fee = ! empty( $scheme_data[ 'subscription_sign_up_fee' ] ) ? $scheme_data[ 'subscription_sign_up_fee' ] : '';
79
-			$subscription_trial_length = isset( $scheme_data[ 'subscription_trial_length' ] ) ? $scheme_data[ 'subscription_trial_length' ] : 0;
80
-			$subscription_trial_period = isset( $scheme_data[ 'subscription_trial_period' ] ) ? $scheme_data[ 'subscription_trial_period' ] : '';
81
-		} else {
82
-			$subscription_sign_up_fee = '';
83
-			$subscription_trial_length = 0;
84
-			$subscription_trial_period = '';
85
-		}
86
-
87
-		echo '<div class="options_group subscription_scheme_product_data sign_up_trial_scheme">';
88
-
89
-		// Sign-up Fee
90
-		woocommerce_wp_text_input( array(
91
-			'id'          => '_subscription_sign_up_fee',
92
-			'class'       => 'wc_input_subscription_intial_price',
93
-			// translators: %s is a currency symbol / code
94
-			'label'       => sprintf( __( 'Sign-up Fee (%s)', WCSATT_STT::TEXT_DOMAIN ), get_woocommerce_currency_symbol() ),
95
-			'placeholder' => _x( 'e.g. 9.90', 'example price', WCSATT_STT::TEXT_DOMAIN ),
96
-			'description' => __( 'Optionally include an amount to be charged at the outset of the subscription. The sign-up fee will be charged immediately, even if the product has a free trial or the payment dates are synced.', WCSATT_STT::TEXT_DOMAIN ),
97
-			'desc_tip'    => true,
98
-			'type'        => 'text',
99
-			'custom_attributes' => array(
100
-				'step' => 'any',
101
-				'min'  => '0',
102
-			),
103
-			'name'        => 'wcsatt_schemes[' . $index . '][subscription_sign_up_fee]',
104
-			'value'       => $subscription_sign_up_fee
105
-		) );
106
-
107
-		echo '<div class="subscription_trial">';
108
-
109
-		// Trial Length
110
-		woocommerce_wp_text_input( array(
111
-			'id'          => '_subscription_trial_length',
112
-			'class'       => 'wc_input_subscription_trial_length',
113
-			'label'       => __( 'Free Trial', WCSATT_STT::TEXT_DOMAIN ),
114
-			'name'        => 'wcsatt_schemes[' . $index . '][subscription_trial_length]',
115
-			'value'       => $subscription_trial_length
116
-		) );
117
-
118
-		// Trial Period
119
-		woocommerce_wp_select( array(
120
-			'id'          => '_subscription_trial_period',
121
-			'class'       => 'wc_input_subscription_trial_period',
122
-			'label'       => __( 'Subscription Trial Period', WCSATT_STT::TEXT_DOMAIN ),
123
-			'options'     => wcs_get_available_time_periods(),
124
-			// translators: placeholder is trial period validation message if passed an invalid value (e.g. "Trial period can not exceed 4 weeks")
125
-			'description' => sprintf( _x( 'An optional period of time to wait before charging the first recurring payment. Any sign up fee will still be charged at the outset of the subscription. %s', 'Trial period dropdown\'s description in pricing fields', WCSATT_STT::TEXT_DOMAIN ), WC_Subscriptions_Admin::get_trial_period_validation_message() ),
126
-			'desc_tip'    => true,
127
-			'value'       => WC_Subscriptions_Product::get_trial_period( $post_id ), // Explicitly set value in to ensure backward compatibility
128
-			'name'        => 'wcsatt_schemes[' . $index . '][subscription_trial_period]',
129
-			'value'       => $subscription_trial_period
130
-	) );
131
-
132
-		echo '</div>';
133
-
134
-		echo '</div>';
135
-	} // END wcsatt_stt_fields()
136
-
137
-	/**
138
-	 * Filters the subscription scheme data to pass the 
139
-	 * sign up and trial options when saving.
140
-	 *
141
-	 * @access public
142
-	 * @static
143
-	 * @param  ini    $posted_scheme
144
-	 * @param  string $product_type
145
-	 * @return void
146
-	 */
147
-	public static function wcsatt_stt_process_scheme_data( $posted_scheme, $product_type ) {
148
-		// Copy variable type fields.
149
-		if ( 'variable' == $product_type ) {
150
-			if ( isset( $posted_scheme[ 'subscription_sign_up_fee_variable' ] ) ) {
151
-				$posted_scheme[ 'subscription_sign_up_fee' ] = $posted_scheme[ 'subscription_sign_up_fee_variable' ];
152
-			}
153
-			if ( isset( $posted_scheme[ 'subscription_trial_length_variable' ] ) ) {
154
-				$posted_scheme[ 'subscription_trial_length' ] = $posted_scheme[ 'subscription_trial_length_variable' ];
155
-			}
156
-			if ( isset( $posted_scheme[ 'subscription_trial_period_variable' ] ) ) {
157
-				$posted_scheme[ 'subscription_trial_period' ] = $posted_scheme[ 'subscription_trial_period_variable'];
158
-			}
159
-		}
160
-
161
-		// Format subscription sign up fee.
162
-		if ( isset( $posted_scheme[ 'subscription_sign_up_fee' ] ) ) {
163
-			$posted_scheme[ 'subscription_sign_up_fee' ] = ( $posted_scheme[ 'subscription_sign_up_fee' ] === '' ) ? '' : wc_format_decimal( $posted_scheme[ 'subscription_sign_up_fee' ] );
164
-		}
165
-
166
-		// Make sure trial period is within allowable range.
167
-		$subscription_ranges = wcs_get_subscription_ranges();
168
-		$max_trial_length = count( $subscription_ranges[ $posted_scheme[ 'subscription_trial_period' ] ] ) - 1;
169
-
170
-		// Format subscription trial length.
171
-		if ( isset( $posted_scheme[ 'subscription_trial_length' ] ) && $posted_scheme[ 'subscription_trial_length' ] > $max_trial_length ) {
172
-			$posted_scheme[ 'subscription_trial_length' ] = ( $posted_scheme[ 'subscription_trial_length' ] === '' ) ? '' : absint( $posted_scheme[ 'subscription_trial_length' ] );
173
-		}
174
-
175
-		// Format subscription trial period.
176
-		$trial_periods = apply_filters( 'wcsatt_stt_trial_periods', array( 'day', 'week', 'month', 'year' ) );
177
-		if ( isset( $posted_scheme[ 'subscription_trial_period' ] ) && in_array( $posted_scheme[ 'subscription_trial_period' ], $trial_periods ) ) {
178
-			$posted_scheme[ 'subscription_trial_period' ] = trim( $posted_scheme[ 'subscription_trial_period' ] );
179
-		}
180
-
181
-		return $posted_scheme;
182
-	} // END wcsatt_stt_process_scheme_data()
11
+    /**
12
+     * Initialize the product meta.
13
+     *
14
+     * @access public
15
+     * @static
16
+     */
17
+    public static function init() {
18
+        // Admin scripts and styles.
19
+        add_action( 'admin_enqueue_scripts', __CLASS__ . '::admin_style' );
20
+
21
+        // Adds to the default values for subscriptions schemes content.
22
+        add_filter( 'wcsatt_default_subscription_scheme', __CLASS__ . '::subscription_schemes_content', 10, 1 );
23
+
24
+        // Subscription scheme options displayed on the 'wcsatt_subscription_scheme_product_content' action.
25
+        add_action( 'wcsatt_subscription_scheme_product_content', __CLASS__ . '::wcsatt_stt_fields', 15, 3 );
26
+
27
+        // Filter the subscription scheme data to process the sign up and trial options on the ''wcsatt_subscription_scheme_process_scheme_data' filter.
28
+        add_filter( 'wcsatt_subscription_scheme_process_scheme_data', __CLASS__ . '::wcsatt_stt_process_scheme_data', 10, 2 );
29
+    }
30
+
31
+    /**
32
+     * Load style.
33
+     *
34
+     * @return void
35
+     */
36
+    public static function admin_style() {
37
+        // Get admin screen id.
38
+        $screen    = get_current_screen();
39
+        $screen_id = $screen ? $screen->id : '';
40
+
41
+        if ( in_array( $screen_id, array( 'edit-product', 'product' ) ) ) {
42
+            wp_register_style( 'wcsatt_stt_writepanel', WCSATT_STT::plugin_url() . '/assets/css/wcsatt-stt-write-panel.css', array( 'woocommerce_admin_styles' ), WCSATT_STT::VERSION );
43
+            wp_enqueue_style( 'wcsatt_stt_writepanel' );
44
+        }
45
+
46
+    } // END admin_style()
47
+
48
+    /**
49
+     * Adds the default values for subscriptions schemes content.
50
+     *
51
+     * @access public
52
+     * @static
53
+     * @param  array $defaults
54
+     * @return void
55
+     */
56
+    public static function subscription_schemes_content( $defaults ) {
57
+        $new_defaults = array(
58
+            'subscription_sign_up_fee'  => '',
59
+            'subscription_trial_length' => '',
60
+            'subscription_trial_period' => ''
61
+        );
62
+
63
+        return array_merge( $new_defaults, $defaults );
64
+    } // END subscription_schemes_content()
65
+
66
+    /**
67
+     * Adds the trial and sign up fields under the subscription section.
68
+     *
69
+     * @access public
70
+     * @static
71
+     * @param  int   $index
72
+     * @param  array $scheme_data
73
+     * @param  int   $post_id
74
+     * @return void
75
+     */
76
+    public static function wcsatt_stt_fields( $index, $scheme_data, $post_id ) {
77
+        if ( ! empty( $scheme_data ) ) {
78
+            $subscription_sign_up_fee = ! empty( $scheme_data[ 'subscription_sign_up_fee' ] ) ? $scheme_data[ 'subscription_sign_up_fee' ] : '';
79
+            $subscription_trial_length = isset( $scheme_data[ 'subscription_trial_length' ] ) ? $scheme_data[ 'subscription_trial_length' ] : 0;
80
+            $subscription_trial_period = isset( $scheme_data[ 'subscription_trial_period' ] ) ? $scheme_data[ 'subscription_trial_period' ] : '';
81
+        } else {
82
+            $subscription_sign_up_fee = '';
83
+            $subscription_trial_length = 0;
84
+            $subscription_trial_period = '';
85
+        }
86
+
87
+        echo '<div class="options_group subscription_scheme_product_data sign_up_trial_scheme">';
88
+
89
+        // Sign-up Fee
90
+        woocommerce_wp_text_input( array(
91
+            'id'          => '_subscription_sign_up_fee',
92
+            'class'       => 'wc_input_subscription_intial_price',
93
+            // translators: %s is a currency symbol / code
94
+            'label'       => sprintf( __( 'Sign-up Fee (%s)', WCSATT_STT::TEXT_DOMAIN ), get_woocommerce_currency_symbol() ),
95
+            'placeholder' => _x( 'e.g. 9.90', 'example price', WCSATT_STT::TEXT_DOMAIN ),
96
+            'description' => __( 'Optionally include an amount to be charged at the outset of the subscription. The sign-up fee will be charged immediately, even if the product has a free trial or the payment dates are synced.', WCSATT_STT::TEXT_DOMAIN ),
97
+            'desc_tip'    => true,
98
+            'type'        => 'text',
99
+            'custom_attributes' => array(
100
+                'step' => 'any',
101
+                'min'  => '0',
102
+            ),
103
+            'name'        => 'wcsatt_schemes[' . $index . '][subscription_sign_up_fee]',
104
+            'value'       => $subscription_sign_up_fee
105
+        ) );
106
+
107
+        echo '<div class="subscription_trial">';
108
+
109
+        // Trial Length
110
+        woocommerce_wp_text_input( array(
111
+            'id'          => '_subscription_trial_length',
112
+            'class'       => 'wc_input_subscription_trial_length',
113
+            'label'       => __( 'Free Trial', WCSATT_STT::TEXT_DOMAIN ),
114
+            'name'        => 'wcsatt_schemes[' . $index . '][subscription_trial_length]',
115
+            'value'       => $subscription_trial_length
116
+        ) );
117
+
118
+        // Trial Period
119
+        woocommerce_wp_select( array(
120
+            'id'          => '_subscription_trial_period',
121
+            'class'       => 'wc_input_subscription_trial_period',
122
+            'label'       => __( 'Subscription Trial Period', WCSATT_STT::TEXT_DOMAIN ),
123
+            'options'     => wcs_get_available_time_periods(),
124
+            // translators: placeholder is trial period validation message if passed an invalid value (e.g. "Trial period can not exceed 4 weeks")
125
+            'description' => sprintf( _x( 'An optional period of time to wait before charging the first recurring payment. Any sign up fee will still be charged at the outset of the subscription. %s', 'Trial period dropdown\'s description in pricing fields', WCSATT_STT::TEXT_DOMAIN ), WC_Subscriptions_Admin::get_trial_period_validation_message() ),
126
+            'desc_tip'    => true,
127
+            'value'       => WC_Subscriptions_Product::get_trial_period( $post_id ), // Explicitly set value in to ensure backward compatibility
128
+            'name'        => 'wcsatt_schemes[' . $index . '][subscription_trial_period]',
129
+            'value'       => $subscription_trial_period
130
+    ) );
131
+
132
+        echo '</div>';
133
+
134
+        echo '</div>';
135
+    } // END wcsatt_stt_fields()
136
+
137
+    /**
138
+     * Filters the subscription scheme data to pass the 
139
+     * sign up and trial options when saving.
140
+     *
141
+     * @access public
142
+     * @static
143
+     * @param  ini    $posted_scheme
144
+     * @param  string $product_type
145
+     * @return void
146
+     */
147
+    public static function wcsatt_stt_process_scheme_data( $posted_scheme, $product_type ) {
148
+        // Copy variable type fields.
149
+        if ( 'variable' == $product_type ) {
150
+            if ( isset( $posted_scheme[ 'subscription_sign_up_fee_variable' ] ) ) {
151
+                $posted_scheme[ 'subscription_sign_up_fee' ] = $posted_scheme[ 'subscription_sign_up_fee_variable' ];
152
+            }
153
+            if ( isset( $posted_scheme[ 'subscription_trial_length_variable' ] ) ) {
154
+                $posted_scheme[ 'subscription_trial_length' ] = $posted_scheme[ 'subscription_trial_length_variable' ];
155
+            }
156
+            if ( isset( $posted_scheme[ 'subscription_trial_period_variable' ] ) ) {
157
+                $posted_scheme[ 'subscription_trial_period' ] = $posted_scheme[ 'subscription_trial_period_variable'];
158
+            }
159
+        }
160
+
161
+        // Format subscription sign up fee.
162
+        if ( isset( $posted_scheme[ 'subscription_sign_up_fee' ] ) ) {
163
+            $posted_scheme[ 'subscription_sign_up_fee' ] = ( $posted_scheme[ 'subscription_sign_up_fee' ] === '' ) ? '' : wc_format_decimal( $posted_scheme[ 'subscription_sign_up_fee' ] );
164
+        }
165
+
166
+        // Make sure trial period is within allowable range.
167
+        $subscription_ranges = wcs_get_subscription_ranges();
168
+        $max_trial_length = count( $subscription_ranges[ $posted_scheme[ 'subscription_trial_period' ] ] ) - 1;
169
+
170
+        // Format subscription trial length.
171
+        if ( isset( $posted_scheme[ 'subscription_trial_length' ] ) && $posted_scheme[ 'subscription_trial_length' ] > $max_trial_length ) {
172
+            $posted_scheme[ 'subscription_trial_length' ] = ( $posted_scheme[ 'subscription_trial_length' ] === '' ) ? '' : absint( $posted_scheme[ 'subscription_trial_length' ] );
173
+        }
174
+
175
+        // Format subscription trial period.
176
+        $trial_periods = apply_filters( 'wcsatt_stt_trial_periods', array( 'day', 'week', 'month', 'year' ) );
177
+        if ( isset( $posted_scheme[ 'subscription_trial_period' ] ) && in_array( $posted_scheme[ 'subscription_trial_period' ], $trial_periods ) ) {
178
+            $posted_scheme[ 'subscription_trial_period' ] = trim( $posted_scheme[ 'subscription_trial_period' ] );
179
+        }
180
+
181
+        return $posted_scheme;
182
+    } // END wcsatt_stt_process_scheme_data()
183 183
 
184 184
 }
185 185
 
Please login to merge, or discard this patch.
wc-satt-stt.php 1 patch
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -20,156 +20,156 @@
 block discarded – undo
20 20
 if ( ! defined('ABSPATH') ) exit; // Exit if accessed directly.
21 21
 
22 22
 if ( ! class_exists( 'WCSATT_STT' ) ) {
23
-	class WCSATT_STT {
24
-
25
-		/* Plugin version. */
26
-		const VERSION = '1.0.1';
27
-
28
-		/* Required WC version. */
29
-		const REQ_WC_VERSION = '2.3.0';
30
-
31
-		/* Required WCSATT version */
32
-		const REQ_WCSATT_VERSION = '1.1.0';
33
-
34
-		/* Text domain. */
35
-		const TEXT_DOMAIN = 'wc-satt-stt';
36
-
37
-		/**
38
-		 * @var WCSATT_STT - the single instance of the class.
39
-		 *
40
-		 * @since 1.0.0
41
-		 */
42
-		protected static $_instance = null;
43
-
44
-		/**
45
-		 * Main WCSATT_STT Instance.
46
-		 *
47
-		 * Ensures only one instance of WCSATT_STT is loaded or can be loaded.
48
-		 *
49
-		 * @static
50
-		 * @see WCSATT_STT()
51
-		 * @return WCSATT_STT - Main instance
52
-		 * @since 1.0.0
53
-		 */
54
-		public static function instance() {
55
-			if ( is_null( self::$_instance ) ) {
56
-				self::$_instance = new self();
57
-			}
58
-			return self::$_instance;
59
-		}
60
-
61
-		/**
62
-		 * Cloning is forbidden.
63
-		 *
64
-		 * @since 1.0.0
65
-		 */
66
-		public function __clone() {
67
-			_doing_it_wrong( __FUNCTION__, __( 'Foul!' ), '1.0.0' );
68
-		}
69
-
70
-		/**
71
-		 * Unserializing instances of this class is forbidden.
72
-		 *
73
-		 * @since 1.0.0
74
-		 */
75
-		public function __wakeup() {
76
-			_doing_it_wrong( __FUNCTION__, __( 'Foul!' ), '1.0.0' );
77
-		}
78
-
79
-		/**
80
-		 * Load the plugin.
81
-		 */
82
-		public function __construct() {
83
-			add_action( 'plugins_loaded', array( $this, 'load_plugin' ), 11 );
84
-			add_action( 'init', array( $this, 'init_plugin' ) );
85
-			add_filter( 'plugin_row_meta', array( $this, 'plugin_meta_links' ), 10, 4 );
86
-		}
87
-
88
-		public static function plugin_url() {
89
-			return plugins_url( basename( plugin_dir_path(__FILE__) ), basename( __FILE__ ) );
90
-		} // END plugin_url()
91
-
92
-		public static function plugin_path() {
93
-			return untrailingslashit( plugin_dir_path( __FILE__ ) );
94
-		} // END plugin_path()
95
-
96
-		/*
23
+    class WCSATT_STT {
24
+
25
+        /* Plugin version. */
26
+        const VERSION = '1.0.1';
27
+
28
+        /* Required WC version. */
29
+        const REQ_WC_VERSION = '2.3.0';
30
+
31
+        /* Required WCSATT version */
32
+        const REQ_WCSATT_VERSION = '1.1.0';
33
+
34
+        /* Text domain. */
35
+        const TEXT_DOMAIN = 'wc-satt-stt';
36
+
37
+        /**
38
+         * @var WCSATT_STT - the single instance of the class.
39
+         *
40
+         * @since 1.0.0
41
+         */
42
+        protected static $_instance = null;
43
+
44
+        /**
45
+         * Main WCSATT_STT Instance.
46
+         *
47
+         * Ensures only one instance of WCSATT_STT is loaded or can be loaded.
48
+         *
49
+         * @static
50
+         * @see WCSATT_STT()
51
+         * @return WCSATT_STT - Main instance
52
+         * @since 1.0.0
53
+         */
54
+        public static function instance() {
55
+            if ( is_null( self::$_instance ) ) {
56
+                self::$_instance = new self();
57
+            }
58
+            return self::$_instance;
59
+        }
60
+
61
+        /**
62
+         * Cloning is forbidden.
63
+         *
64
+         * @since 1.0.0
65
+         */
66
+        public function __clone() {
67
+            _doing_it_wrong( __FUNCTION__, __( 'Foul!' ), '1.0.0' );
68
+        }
69
+
70
+        /**
71
+         * Unserializing instances of this class is forbidden.
72
+         *
73
+         * @since 1.0.0
74
+         */
75
+        public function __wakeup() {
76
+            _doing_it_wrong( __FUNCTION__, __( 'Foul!' ), '1.0.0' );
77
+        }
78
+
79
+        /**
80
+         * Load the plugin.
81
+         */
82
+        public function __construct() {
83
+            add_action( 'plugins_loaded', array( $this, 'load_plugin' ), 11 );
84
+            add_action( 'init', array( $this, 'init_plugin' ) );
85
+            add_filter( 'plugin_row_meta', array( $this, 'plugin_meta_links' ), 10, 4 );
86
+        }
87
+
88
+        public static function plugin_url() {
89
+            return plugins_url( basename( plugin_dir_path(__FILE__) ), basename( __FILE__ ) );
90
+        } // END plugin_url()
91
+
92
+        public static function plugin_path() {
93
+            return untrailingslashit( plugin_dir_path( __FILE__ ) );
94
+        } // END plugin_path()
95
+
96
+        /*
97 97
 		 * Check requirements on activation.
98 98
 		 *
99 99
 		 * @global $woocommerce
100 100
 		 */
101
-		public function load_plugin() {
102
-			global $woocommerce;
103
-
104
-			// Check that the required WooCommerce is running.
105
-			if ( version_compare( $woocommerce->version, self::REQ_WC_VERSION, '<' ) ) {
106
-				add_action( 'admin_notices', array( $this, 'wcsatt_stt_wc_admin_notice' ) );
107
-				return false;
108
-			}
109
-
110
-			// Checks that WooCommerce Subscribe All the Things is running or is less than the required version.
111
-			if ( ! class_exists( 'WCS_ATT' ) || version_compare( WCS_ATT::VERSION, self::REQ_WCSATT_VERSION, '<' ) ) {
112
-				add_action( 'admin_notices', array( $this, 'wcsatt_stt_admin_notice' ) );
113
-				return false;
114
-			}
115
-
116
-			require_once( 'includes/class-wcsatt-stt-cart.php' );
117
-			require_once( 'includes/class-wcsatt-stt-display.php' );
118
-
119
-			// Admin includes
120
-			if ( is_admin() ) {
121
-				require_once( 'includes/admin/class-wcsatt-stt-admin.php' );
122
-			}
123
-
124
-		} // END load_plugin()
125
-
126
-		/**
127
-		 * Display a warning message if minimum version of WooCommerce check fails.
128
-		 *
129
-		 * @return void
130
-		 */
131
-		public function wcsatt_stt_wc_admin_notice() {
132
-			echo '<div class="error"><p>' . sprintf( __( '%1$s requires at least %2$s v%3$s in order to function. Please upgrade %2$s.', 'wc-satt-stt' ), 'WooCommerce Subscribe All the Things: Sign-up and Trial Add-on', 'WooCommerce', self::REQ_WC_VERSION ) . '</p></div>';
133
-		} // END wcsatt_stt_wc_admin_notice()
134
-
135
-		/**
136
-		 * Display a warning message if minimum version of WooCommerce Subscribe All the Things check fails.
137
-		 *
138
-		 * @return void
139
-		 */
140
-		public function wcsatt_stt_admin_notice() {
141
-			echo '<div class="error"><p>' . sprintf( __( '%1$s requires at least %2$s v%3$s in order to function. Please upgrade %2$s.', 'wc-satt-stt' ), 'WooCommerce Subscribe All the Things: Sign-up and Trial Add-on', 'WooCommerce Subscribe All the Things', self::REQ_WCSATT_VERSION ) . '</p></div>';
142
-		} // END wcsatt_stt_admin_notice()
143
-
144
-		/**
145
-		 * Initialize the plugin if ready.
146
-		 *
147
-		 * @return void
148
-		 */
149
-		public function init_plugin() {
150
-			// Load text domain.
151
-			load_plugin_textdomain( 'wc-satt-stt', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
152
-		} // END init_plugin()
153
-
154
-		/**
155
-		 * Show row meta on the plugin screen.
156
-		 *
157
-		 * @param  mixed $links Plugin Row Meta
158
-		 * @param  mixed $file  Plugin Base file
159
-		 * @param  array $data  Plugin Data
160
-		 * @return array
161
-		 */
162
-		public function plugin_meta_links( $links, $file, $data, $status ) {
163
-			if ( $file == plugin_basename( __FILE__ ) ) {
164
-				$author1 = '<a href="' . $data[ 'AuthorURI' ] . '">' . $data[ 'Author' ] . '</a>';
165
-				$author2 = '<a href="http://www.subscriptiongroup.co.uk/">Subscription Group Limited</a>';
166
-				$links[ 1 ] = sprintf( __( 'By %s', self::TEXT_DOMAIN ), sprintf( __( '%s and %s', self::TEXT_DOMAIN ), $author1, $author2 ) );
167
-			}
168
-
169
-			return $links;
170
-		} // END plugin_meta_links()
171
-
172
-	} // END class
101
+        public function load_plugin() {
102
+            global $woocommerce;
103
+
104
+            // Check that the required WooCommerce is running.
105
+            if ( version_compare( $woocommerce->version, self::REQ_WC_VERSION, '<' ) ) {
106
+                add_action( 'admin_notices', array( $this, 'wcsatt_stt_wc_admin_notice' ) );
107
+                return false;
108
+            }
109
+
110
+            // Checks that WooCommerce Subscribe All the Things is running or is less than the required version.
111
+            if ( ! class_exists( 'WCS_ATT' ) || version_compare( WCS_ATT::VERSION, self::REQ_WCSATT_VERSION, '<' ) ) {
112
+                add_action( 'admin_notices', array( $this, 'wcsatt_stt_admin_notice' ) );
113
+                return false;
114
+            }
115
+
116
+            require_once( 'includes/class-wcsatt-stt-cart.php' );
117
+            require_once( 'includes/class-wcsatt-stt-display.php' );
118
+
119
+            // Admin includes
120
+            if ( is_admin() ) {
121
+                require_once( 'includes/admin/class-wcsatt-stt-admin.php' );
122
+            }
123
+
124
+        } // END load_plugin()
125
+
126
+        /**
127
+         * Display a warning message if minimum version of WooCommerce check fails.
128
+         *
129
+         * @return void
130
+         */
131
+        public function wcsatt_stt_wc_admin_notice() {
132
+            echo '<div class="error"><p>' . sprintf( __( '%1$s requires at least %2$s v%3$s in order to function. Please upgrade %2$s.', 'wc-satt-stt' ), 'WooCommerce Subscribe All the Things: Sign-up and Trial Add-on', 'WooCommerce', self::REQ_WC_VERSION ) . '</p></div>';
133
+        } // END wcsatt_stt_wc_admin_notice()
134
+
135
+        /**
136
+         * Display a warning message if minimum version of WooCommerce Subscribe All the Things check fails.
137
+         *
138
+         * @return void
139
+         */
140
+        public function wcsatt_stt_admin_notice() {
141
+            echo '<div class="error"><p>' . sprintf( __( '%1$s requires at least %2$s v%3$s in order to function. Please upgrade %2$s.', 'wc-satt-stt' ), 'WooCommerce Subscribe All the Things: Sign-up and Trial Add-on', 'WooCommerce Subscribe All the Things', self::REQ_WCSATT_VERSION ) . '</p></div>';
142
+        } // END wcsatt_stt_admin_notice()
143
+
144
+        /**
145
+         * Initialize the plugin if ready.
146
+         *
147
+         * @return void
148
+         */
149
+        public function init_plugin() {
150
+            // Load text domain.
151
+            load_plugin_textdomain( 'wc-satt-stt', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
152
+        } // END init_plugin()
153
+
154
+        /**
155
+         * Show row meta on the plugin screen.
156
+         *
157
+         * @param  mixed $links Plugin Row Meta
158
+         * @param  mixed $file  Plugin Base file
159
+         * @param  array $data  Plugin Data
160
+         * @return array
161
+         */
162
+        public function plugin_meta_links( $links, $file, $data, $status ) {
163
+            if ( $file == plugin_basename( __FILE__ ) ) {
164
+                $author1 = '<a href="' . $data[ 'AuthorURI' ] . '">' . $data[ 'Author' ] . '</a>';
165
+                $author2 = '<a href="http://www.subscriptiongroup.co.uk/">Subscription Group Limited</a>';
166
+                $links[ 1 ] = sprintf( __( 'By %s', self::TEXT_DOMAIN ), sprintf( __( '%s and %s', self::TEXT_DOMAIN ), $author1, $author2 ) );
167
+            }
168
+
169
+            return $links;
170
+        } // END plugin_meta_links()
171
+
172
+    } // END class
173 173
 
174 174
 } // END if class exists
175 175
 
Please login to merge, or discard this patch.