Completed
Push — master ( d92bae...5ead7b )
by Sébastien
02:37
created
wc-satt-stt.php 2 patches
Indentation   +450 added lines, -450 removed lines patch added patch discarded remove patch
@@ -20,367 +20,367 @@  discard block
 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.0';
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.1';
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' ) );
84
-			add_action( 'init', array( $this, 'init_plugin' ) );
85
-			add_action( 'admin_init', array( $this, 'admin_wcsatt_stt_product_meta' ) );
86
-			add_filter( 'plugin_row_meta', array( $this, 'plugin_meta_links' ), 10, 4 );
87
-		}
88
-
89
-		public function plugin_path() {
90
-			return untrailingslashit( plugin_dir_path( __FILE__ ) );
91
-		} // END plugin_path()
92
-
93
-		/*
23
+    class WCSATT_STT {
24
+
25
+        /* Plugin version. */
26
+        const VERSION = '1.0.0';
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.1';
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' ) );
84
+            add_action( 'init', array( $this, 'init_plugin' ) );
85
+            add_action( 'admin_init', array( $this, 'admin_wcsatt_stt_product_meta' ) );
86
+            add_filter( 'plugin_row_meta', array( $this, 'plugin_meta_links' ), 10, 4 );
87
+        }
88
+
89
+        public function plugin_path() {
90
+            return untrailingslashit( plugin_dir_path( __FILE__ ) );
91
+        } // END plugin_path()
92
+
93
+        /*
94 94
 		 * Check requirements on activation.
95 95
 		 */
96
-		public function load_plugin() {
97
-			global $woocommerce;
98
-
99
-			// Check that the required WooCommerce is running.
100
-			if ( version_compare( $woocommerce->version, self::REQ_WC_VERSION, '<' ) ) {
101
-				add_action( 'admin_notices', array( $this, 'wcsatt_stt_wc_admin_notice' ) );
102
-				return false;
103
-			}
104
-
105
-			// Checks that WooCommerce Subscribe All the Things is running or is less than the required version.
106
-			if ( ! class_exists( 'WCS_ATT' ) || version_compare( WCS_ATT::VERSION, self::REQ_WCSATT_VERSION, '<' ) ) {
107
-				add_action( 'admin_notices', array( $this, 'wcsatt_stt_admin_notice' ) );
108
-				return false;
109
-			}
110
-		} // END load_plugin()
111
-
112
-		/**
113
-		 * Display a warning message if minimum version of WooCommerce check fails.
114
-		 *
115
-		 * @return void
116
-		 */
117
-		public function wcsatt_stt_wc_admin_notice() {
118
-			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' ), 'Sign up and Trial Options Add-on for WCSATT', 'WooCommerce', self::REQ_WC_VERSION ) . '</p></div>';
119
-		} // END wcsatt_stt_wc_admin_notice()
120
-
121
-		/**
122
-		 * Display a warning message if minimum version of WooCommerce Subscribe to All the Things check fails.
123
-		 *
124
-		 * @return void
125
-		 */
126
-		public function wcsatt_stt_admin_notice() {
127
-			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' ), 'Sign up and Trial Options Add-on', 'WooCommerce Subscribe to All the Things', self::REQ_WCSATT_VERSION ) . '</p></div>';
128
-		} // END wcsatt_stt_admin_notice()
129
-
130
-		/**
131
-		 * Initialize the plugin if ready.
132
-		 *
133
-		 * @return void
134
-		 */
135
-		public function init_plugin() {
136
-			// Load text domain.
137
-			load_plugin_textdomain( 'wc-satt-stt', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
138
-
139
-			// Adds the sign up fee and trial data to the price html on the 'wcsatt_overridden_subscription_prices_product' filter.
140
-			add_filter( 'wcsatt_overridden_subscription_prices_product', array( $this, 'add_sub_scheme_data_price_html' ), 10, 3 );
141
-
142
-			// Adds the extra subscription scheme data to the product object.
143
-			add_filter( 'wcsatt_sub_product_scheme_option', array( $this, 'sub_product_scheme_option' ), 10, 2 );
144
-
145
-			// Filters the price string to include the sign up fee and/or trial to pass per scheme option.
146
-			add_filter( 'wcsatt_get_single_product_price_string', array( $this, 'get_price_string' ), 10, 2 );
147
-
148
-			// Filters the suffix price html on the 'wcsatt_suffix_price_html' filter.
149
-			//add_filter( 'wcsatt_suffix_price_html', array( $this, 'filter_suffix_price_html' ), 10, 1 );
150
-
151
-			// Overrides the price of the subscription for sign up fee and/or trial on the 'woocommerce_add_cart_item' filter.
152
-			add_filter( 'woocommerce_add_cart_item', array( $this, 'add_cart_item' ), 15, 1 );
153
-		} // END init_plugin()
154
-
155
-		/**
156
-		 * Register the product meta data fields.
157
-		 *
158
-		 * @return void
159
-		 */
160
-		public function admin_wcsatt_stt_product_meta() {
161
-			// Subscription scheme options displayed on the 'wcsatt_subscription_scheme_content' action.
162
-			//add_action( 'wcsatt_subscription_scheme_content', array( $this, 'wcsatt_stt_fields' ), 15, 3 );
163
-
164
-			// Subscription scheme options displayed on the 'wcsatt_subscription_scheme_product_content' action.
165
-			add_action( 'wcsatt_subscription_scheme_product_content', array( $this, 'wcsatt_stt_fields' ), 15, 3 );
166
-
167
-			// Filter the subscription scheme data to process the sign up and trial options on the ''wcsatt_subscription_scheme_process_scheme_data' filter.
168
-			add_filter( 'wcsatt_subscription_scheme_process_scheme_data', array( $this, 'wcsatt_stt_process_scheme_data' ), 10, 2 );
169
-		} // END admin_wcsatt_stt_product_meta()
170
-
171
-		/**
172
-		 * Show row meta on the plugin screen.
173
-		 *
174
-		 * @param mixed $links Plugin Row Meta
175
-		 * @param mixed $file  Plugin Base file
176
-		 * @return array
177
-		 */
178
-		public function plugin_meta_links( $links, $file, $data, $status ) {
179
-			if ( $file == plugin_basename( __FILE__ ) ) {
180
-				$author1 = '<a href="' . $data[ 'AuthorURI' ] . '">' . $data[ 'Author' ] . '</a>';
181
-				$links[ 1 ] = sprintf( __( 'By %s', WCSATT_STT::TEXT_DOMAIN ), $author1 );
182
-			}
183
-
184
-			return $links;
185
-		} // END plugin_meta_links()
186
-
187
-		/**
188
-		 * Adds the default values for subscriptions schemes content.
189
-		 *
190
-		 * @param  array $defaults
191
-		 * @return void
192
-		 */
193
-		public static function add_default_subscription_schemes_content( $defaults ) {
194
-			$new_defaults = array(
195
-				'subscription_sign_up_fee'  => '',
196
-				'subscription_trial_length' => '',
197
-				'subscription_trial_period' => ''
198
-			);
199
-
200
-			return array_merge( $new_defaults, $defaults );
201
-		} // END add_default_subscription_schemes_content()
202
-
203
-		/**
204
-		 * Adds the trial and sign up fields under the subscription section.
205
-		 *
206
-		 * @param  int   $index
207
-		 * @param  array $scheme_data
208
-		 * @param  int   $post_id
209
-		 * @return void
210
-		 */
211
-		public function wcsatt_stt_fields( $index, $scheme_data, $post_id ) {
212
-			if ( ! empty( $scheme_data ) ) {
213
-				$subscription_sign_up_fee = ! empty( $scheme_data[ 'subscription_sign_up_fee' ] ) ? $scheme_data[ 'subscription_sign_up_fee' ] : '';
214
-				$subscription_trial_length = isset( $scheme_data[ 'subscription_trial_length' ] ) ? $scheme_data[ 'subscription_trial_length' ] : 0;
215
-				$subscription_trial_period = isset( $scheme_data[ 'subscription_trial_period' ] ) ? $scheme_data[ 'subscription_trial_period' ] : '';
216
-			} else {
217
-				$subscription_sign_up_fee = '';
218
-				$subscription_trial_length = 0;
219
-				$subscription_trial_period = '';
220
-			}
221
-
222
-			// Sign-up Fee
223
-			woocommerce_wp_text_input( array(
224
-				'id'          => '_subscription_sign_up_fee',
225
-				'class'       => 'wc_input_subscription_intial_price',
226
-				// translators: %s is a currency symbol / code
227
-				'label'       => sprintf( __( 'Sign-up Fee (%s)', WCSATT_STT::TEXT_DOMAIN ), get_woocommerce_currency_symbol() ),
228
-				'placeholder' => _x( 'e.g. 9.90', 'example price', WCSATT_STT::TEXT_DOMAIN ),
229
-				'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 ),
230
-				'desc_tip'    => true,
231
-				'type'        => 'text',
232
-				'custom_attributes' => array(
233
-					'step' => 'any',
234
-					'min'  => '0',
235
-				),
236
-				'name'        => 'wcsatt_schemes[' . $index . '][subscription_sign_up_fee]',
237
-				'value'       => $subscription_sign_up_fee
238
-			) );
239
-
240
-			// Trial Length
241
-			woocommerce_wp_text_input( array(
242
-				'id'          => '_subscription_trial_length',
243
-				'class'       => 'wc_input_subscription_trial_length',
244
-				'label'       => __( 'Free Trial', WCSATT_STT::TEXT_DOMAIN ),
245
-				'name'        => 'wcsatt_schemes[' . $index . '][subscription_trial_length]',
246
-				'value'       => $subscription_trial_length
247
-			) );
248
-
249
-			// Trial Period
250
-			woocommerce_wp_select( array(
251
-				'id'          => '_subscription_trial_period',
252
-				'class'       => 'wc_input_subscription_trial_period',
253
-				'label'       => __( 'Subscription Trial Period', WCSATT_STT::TEXT_DOMAIN ),
254
-				'options'     => wcs_get_available_time_periods(),
255
-				// translators: placeholder is trial period validation message if passed an invalid value (e.g. "Trial period can not exceed 4 weeks")
256
-				'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() ),
257
-				'desc_tip'    => true,
258
-				'value'       => WC_Subscriptions_Product::get_trial_period( $post_id ), // Explicitly set value in to ensure backward compatibility
259
-				'name'        => 'wcsatt_schemes[' . $index . '][subscription_trial_period]',
260
-				'value'       => $subscription_trial_period
261
-		) );
262
-		} // END wcsatt_stt_fields()
263
-
264
-		/**
265
-		 * Filters the subscription scheme data to pass the 
266
-		 * sign up and trial options when saving.
267
-		 *
268
-		 * @param  ini $posted_scheme
269
-		 * @param  string $product_type
270
-		 * @return void
271
-		 */
272
-		public function wcsatt_stt_process_scheme_data( $posted_scheme, $product_type ) {
273
-			// Copy variable type fields.
274
-			if ( 'variable' == $product_type ) {
275
-				if ( isset( $posted_scheme[ 'subscription_sign_up_fee_variable' ] ) ) {
276
-					$posted_scheme[ 'subscription_sign_up_fee' ] = $posted_scheme[ 'subscription_sign_up_fee_variable' ];
277
-				}
278
-				if ( isset( $posted_scheme[ 'subscription_trial_length_variable' ] ) ) {
279
-					$posted_scheme[ 'subscription_trial_length' ] = $posted_scheme[ 'subscription_trial_length_variable' ];
280
-				}
281
-				if ( isset( $posted_scheme[ 'subscription_trial_period_variable' ] ) ) {
282
-					$posted_scheme[ 'subscription_trial_period' ] = $posted_scheme[ 'subscription_trial_period_variable'];
283
-				}
284
-			}
285
-
286
-			// Format subscription sign up fee.
287
-			if ( isset( $posted_scheme[ 'subscription_sign_up_fee' ] ) ) {
288
-				$posted_scheme[ 'subscription_sign_up_fee' ] = ( $posted_scheme[ 'subscription_sign_up_fee' ] === '' ) ? '' : wc_format_decimal( $posted_scheme[ 'subscription_sign_up_fee' ] );
289
-			}
290
-
291
-			// Make sure trial period is within allowable range.
292
-			$subscription_ranges = wcs_get_subscription_ranges();
293
-			$max_trial_length = count( $subscription_ranges[ $posted_scheme[ 'subscription_trial_period' ] ] ) - 1;
294
-
295
-			// Format subscription trial length.
296
-			if ( isset( $posted_scheme[ 'subscription_trial_length' ] ) && $posted_scheme[ 'subscription_trial_length' ] > $max_trial_length ) {
297
-				$posted_scheme[ 'subscription_trial_length' ] = ( $posted_scheme[ 'subscription_trial_length' ] === '' ) ? '' : absint( $posted_scheme[ 'subscription_trial_length' ] );
298
-			}
299
-
300
-			// Format subscription trial period.
301
-			$trial_periods = apply_filters( 'wcsatt_stt_trial_periods', array( 'day', 'week', 'month', 'year' ) );
302
-			if ( isset( $posted_scheme[ 'subscription_trial_period' ] ) && in_array( $posted_scheme[ 'subscription_trial_period' ], $trial_periods ) ) {
303
-				$posted_scheme[ 'subscription_trial_period' ] = trim( $posted_scheme[ 'subscription_trial_period' ] );
304
-			}
305
-
306
-			return $posted_scheme;
307
-		} // END wcsatt_stt_process_scheme_data()
308
-
309
-		/**
310
-		 * Adds the additional subscription scheme data for products with attached subscription schemes.
311
-		 *
312
-		 * @param  object     $_product
313
-		 * @param  array      $subscription_scheme
314
-		 * @param  WC_Product $product
315
-		 * @return string
316
-		 */
317
-		public function add_sub_scheme_data_price_html( $_product, $subscription_scheme, $product ) {
318
-			if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) ) {
319
-				$_product->subscription_sign_up_fee = $subscription_scheme[ 'subscription_sign_up_fee' ];
320
-			}
321
-
322
-			if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) ) {
323
-				$_product->subscription_trial_length = $subscription_scheme[ 'subscription_trial_length' ];
324
-			}
325
-
326
-			if ( isset( $subscription_scheme[ 'subscription_trial_period' ] ) ) {
327
-				$_product->subscription_trial_period = $subscription_scheme[ 'subscription_trial_period' ];
328
-			}
329
-
330
-			return $_product;
331
-		} // END add_sub_scheme_data_price_html()
332
-
333
-		/**
334
-		 * Adds the extra subscription scheme data to the product object.
335
-		 * This allows the subscription price to change the initial and
336
-		 * recurring subscriptions.
337
-		 *
338
-		 * @param  object $_cloned
339
-		 * @param  array  $subscription_scheme
340
-		 * @return object
341
-		 */
342
-		public function sub_product_scheme_option( $_cloned, $subscription_scheme ) {
343
-			if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) && $subscription_scheme[ 'subscription_sign_up_fee' ] > 0 ) {
344
-				$_cloned->subscription_sign_up_fee = $subscription_scheme[ 'subscription_sign_up_fee' ];
345
-			}
346
-
347
-			if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) && 0 != $subscription_scheme[ 'subscription_trial_length' ] ) {
348
-				$_cloned->subscription_trial_length = $subscription_scheme[ 'subscription_trial_length' ];
349
-				$_cloned->subscription_trial_period = $subscription_scheme[ 'subscription_trial_period' ];
350
-			}
351
-
352
-			return $_cloned;
353
-		} // END sub_product_scheme_option()
354
-
355
-		/**
356
-		 * Filters the price string to include the sign up fee and/or trial 
357
-		 * to pass per subscription scheme option.
358
-		 *
359
-		 * @param  array $prices
360
-		 * @param  array $subscription_scheme
361
-		 * @return array
362
-		 */
363
-		public function get_price_string( $prices, $subscription_scheme ) {
364
-			if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) && $subscription_scheme[ 'subscription_sign_up_fee' ] > 0 ) {
365
-				$prices[ 'sign_up_fee' ] = true;
366
-			}
367
-
368
-			if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) && 0 != $subscription_scheme[ 'subscription_trial_length' ] ) {
369
-				$prices[ 'trial_length' ] = true;
370
-			}
371
-
372
-			return $prices;
373
-		} // END get_price_string()
374
-
375
-		/**
376
-		 * Filter the suffix price string.
377
-		 *
378
-		 * @param object     $_product
379
-		 * @param array      $subscription_scheme
380
-		 * @param WC_Product $product
381
-		 * @return string
382
-		 */
383
-		/*public function filter_suffix_price_html( $_product, $subscription_scheme, $product ) {
96
+        public function load_plugin() {
97
+            global $woocommerce;
98
+
99
+            // Check that the required WooCommerce is running.
100
+            if ( version_compare( $woocommerce->version, self::REQ_WC_VERSION, '<' ) ) {
101
+                add_action( 'admin_notices', array( $this, 'wcsatt_stt_wc_admin_notice' ) );
102
+                return false;
103
+            }
104
+
105
+            // Checks that WooCommerce Subscribe All the Things is running or is less than the required version.
106
+            if ( ! class_exists( 'WCS_ATT' ) || version_compare( WCS_ATT::VERSION, self::REQ_WCSATT_VERSION, '<' ) ) {
107
+                add_action( 'admin_notices', array( $this, 'wcsatt_stt_admin_notice' ) );
108
+                return false;
109
+            }
110
+        } // END load_plugin()
111
+
112
+        /**
113
+         * Display a warning message if minimum version of WooCommerce check fails.
114
+         *
115
+         * @return void
116
+         */
117
+        public function wcsatt_stt_wc_admin_notice() {
118
+            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' ), 'Sign up and Trial Options Add-on for WCSATT', 'WooCommerce', self::REQ_WC_VERSION ) . '</p></div>';
119
+        } // END wcsatt_stt_wc_admin_notice()
120
+
121
+        /**
122
+         * Display a warning message if minimum version of WooCommerce Subscribe to All the Things check fails.
123
+         *
124
+         * @return void
125
+         */
126
+        public function wcsatt_stt_admin_notice() {
127
+            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' ), 'Sign up and Trial Options Add-on', 'WooCommerce Subscribe to All the Things', self::REQ_WCSATT_VERSION ) . '</p></div>';
128
+        } // END wcsatt_stt_admin_notice()
129
+
130
+        /**
131
+         * Initialize the plugin if ready.
132
+         *
133
+         * @return void
134
+         */
135
+        public function init_plugin() {
136
+            // Load text domain.
137
+            load_plugin_textdomain( 'wc-satt-stt', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
138
+
139
+            // Adds the sign up fee and trial data to the price html on the 'wcsatt_overridden_subscription_prices_product' filter.
140
+            add_filter( 'wcsatt_overridden_subscription_prices_product', array( $this, 'add_sub_scheme_data_price_html' ), 10, 3 );
141
+
142
+            // Adds the extra subscription scheme data to the product object.
143
+            add_filter( 'wcsatt_sub_product_scheme_option', array( $this, 'sub_product_scheme_option' ), 10, 2 );
144
+
145
+            // Filters the price string to include the sign up fee and/or trial to pass per scheme option.
146
+            add_filter( 'wcsatt_get_single_product_price_string', array( $this, 'get_price_string' ), 10, 2 );
147
+
148
+            // Filters the suffix price html on the 'wcsatt_suffix_price_html' filter.
149
+            //add_filter( 'wcsatt_suffix_price_html', array( $this, 'filter_suffix_price_html' ), 10, 1 );
150
+
151
+            // Overrides the price of the subscription for sign up fee and/or trial on the 'woocommerce_add_cart_item' filter.
152
+            add_filter( 'woocommerce_add_cart_item', array( $this, 'add_cart_item' ), 15, 1 );
153
+        } // END init_plugin()
154
+
155
+        /**
156
+         * Register the product meta data fields.
157
+         *
158
+         * @return void
159
+         */
160
+        public function admin_wcsatt_stt_product_meta() {
161
+            // Subscription scheme options displayed on the 'wcsatt_subscription_scheme_content' action.
162
+            //add_action( 'wcsatt_subscription_scheme_content', array( $this, 'wcsatt_stt_fields' ), 15, 3 );
163
+
164
+            // Subscription scheme options displayed on the 'wcsatt_subscription_scheme_product_content' action.
165
+            add_action( 'wcsatt_subscription_scheme_product_content', array( $this, 'wcsatt_stt_fields' ), 15, 3 );
166
+
167
+            // Filter the subscription scheme data to process the sign up and trial options on the ''wcsatt_subscription_scheme_process_scheme_data' filter.
168
+            add_filter( 'wcsatt_subscription_scheme_process_scheme_data', array( $this, 'wcsatt_stt_process_scheme_data' ), 10, 2 );
169
+        } // END admin_wcsatt_stt_product_meta()
170
+
171
+        /**
172
+         * Show row meta on the plugin screen.
173
+         *
174
+         * @param mixed $links Plugin Row Meta
175
+         * @param mixed $file  Plugin Base file
176
+         * @return array
177
+         */
178
+        public function plugin_meta_links( $links, $file, $data, $status ) {
179
+            if ( $file == plugin_basename( __FILE__ ) ) {
180
+                $author1 = '<a href="' . $data[ 'AuthorURI' ] . '">' . $data[ 'Author' ] . '</a>';
181
+                $links[ 1 ] = sprintf( __( 'By %s', WCSATT_STT::TEXT_DOMAIN ), $author1 );
182
+            }
183
+
184
+            return $links;
185
+        } // END plugin_meta_links()
186
+
187
+        /**
188
+         * Adds the default values for subscriptions schemes content.
189
+         *
190
+         * @param  array $defaults
191
+         * @return void
192
+         */
193
+        public static function add_default_subscription_schemes_content( $defaults ) {
194
+            $new_defaults = array(
195
+                'subscription_sign_up_fee'  => '',
196
+                'subscription_trial_length' => '',
197
+                'subscription_trial_period' => ''
198
+            );
199
+
200
+            return array_merge( $new_defaults, $defaults );
201
+        } // END add_default_subscription_schemes_content()
202
+
203
+        /**
204
+         * Adds the trial and sign up fields under the subscription section.
205
+         *
206
+         * @param  int   $index
207
+         * @param  array $scheme_data
208
+         * @param  int   $post_id
209
+         * @return void
210
+         */
211
+        public function wcsatt_stt_fields( $index, $scheme_data, $post_id ) {
212
+            if ( ! empty( $scheme_data ) ) {
213
+                $subscription_sign_up_fee = ! empty( $scheme_data[ 'subscription_sign_up_fee' ] ) ? $scheme_data[ 'subscription_sign_up_fee' ] : '';
214
+                $subscription_trial_length = isset( $scheme_data[ 'subscription_trial_length' ] ) ? $scheme_data[ 'subscription_trial_length' ] : 0;
215
+                $subscription_trial_period = isset( $scheme_data[ 'subscription_trial_period' ] ) ? $scheme_data[ 'subscription_trial_period' ] : '';
216
+            } else {
217
+                $subscription_sign_up_fee = '';
218
+                $subscription_trial_length = 0;
219
+                $subscription_trial_period = '';
220
+            }
221
+
222
+            // Sign-up Fee
223
+            woocommerce_wp_text_input( array(
224
+                'id'          => '_subscription_sign_up_fee',
225
+                'class'       => 'wc_input_subscription_intial_price',
226
+                // translators: %s is a currency symbol / code
227
+                'label'       => sprintf( __( 'Sign-up Fee (%s)', WCSATT_STT::TEXT_DOMAIN ), get_woocommerce_currency_symbol() ),
228
+                'placeholder' => _x( 'e.g. 9.90', 'example price', WCSATT_STT::TEXT_DOMAIN ),
229
+                '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 ),
230
+                'desc_tip'    => true,
231
+                'type'        => 'text',
232
+                'custom_attributes' => array(
233
+                    'step' => 'any',
234
+                    'min'  => '0',
235
+                ),
236
+                'name'        => 'wcsatt_schemes[' . $index . '][subscription_sign_up_fee]',
237
+                'value'       => $subscription_sign_up_fee
238
+            ) );
239
+
240
+            // Trial Length
241
+            woocommerce_wp_text_input( array(
242
+                'id'          => '_subscription_trial_length',
243
+                'class'       => 'wc_input_subscription_trial_length',
244
+                'label'       => __( 'Free Trial', WCSATT_STT::TEXT_DOMAIN ),
245
+                'name'        => 'wcsatt_schemes[' . $index . '][subscription_trial_length]',
246
+                'value'       => $subscription_trial_length
247
+            ) );
248
+
249
+            // Trial Period
250
+            woocommerce_wp_select( array(
251
+                'id'          => '_subscription_trial_period',
252
+                'class'       => 'wc_input_subscription_trial_period',
253
+                'label'       => __( 'Subscription Trial Period', WCSATT_STT::TEXT_DOMAIN ),
254
+                'options'     => wcs_get_available_time_periods(),
255
+                // translators: placeholder is trial period validation message if passed an invalid value (e.g. "Trial period can not exceed 4 weeks")
256
+                '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() ),
257
+                'desc_tip'    => true,
258
+                'value'       => WC_Subscriptions_Product::get_trial_period( $post_id ), // Explicitly set value in to ensure backward compatibility
259
+                'name'        => 'wcsatt_schemes[' . $index . '][subscription_trial_period]',
260
+                'value'       => $subscription_trial_period
261
+        ) );
262
+        } // END wcsatt_stt_fields()
263
+
264
+        /**
265
+         * Filters the subscription scheme data to pass the 
266
+         * sign up and trial options when saving.
267
+         *
268
+         * @param  ini $posted_scheme
269
+         * @param  string $product_type
270
+         * @return void
271
+         */
272
+        public function wcsatt_stt_process_scheme_data( $posted_scheme, $product_type ) {
273
+            // Copy variable type fields.
274
+            if ( 'variable' == $product_type ) {
275
+                if ( isset( $posted_scheme[ 'subscription_sign_up_fee_variable' ] ) ) {
276
+                    $posted_scheme[ 'subscription_sign_up_fee' ] = $posted_scheme[ 'subscription_sign_up_fee_variable' ];
277
+                }
278
+                if ( isset( $posted_scheme[ 'subscription_trial_length_variable' ] ) ) {
279
+                    $posted_scheme[ 'subscription_trial_length' ] = $posted_scheme[ 'subscription_trial_length_variable' ];
280
+                }
281
+                if ( isset( $posted_scheme[ 'subscription_trial_period_variable' ] ) ) {
282
+                    $posted_scheme[ 'subscription_trial_period' ] = $posted_scheme[ 'subscription_trial_period_variable'];
283
+                }
284
+            }
285
+
286
+            // Format subscription sign up fee.
287
+            if ( isset( $posted_scheme[ 'subscription_sign_up_fee' ] ) ) {
288
+                $posted_scheme[ 'subscription_sign_up_fee' ] = ( $posted_scheme[ 'subscription_sign_up_fee' ] === '' ) ? '' : wc_format_decimal( $posted_scheme[ 'subscription_sign_up_fee' ] );
289
+            }
290
+
291
+            // Make sure trial period is within allowable range.
292
+            $subscription_ranges = wcs_get_subscription_ranges();
293
+            $max_trial_length = count( $subscription_ranges[ $posted_scheme[ 'subscription_trial_period' ] ] ) - 1;
294
+
295
+            // Format subscription trial length.
296
+            if ( isset( $posted_scheme[ 'subscription_trial_length' ] ) && $posted_scheme[ 'subscription_trial_length' ] > $max_trial_length ) {
297
+                $posted_scheme[ 'subscription_trial_length' ] = ( $posted_scheme[ 'subscription_trial_length' ] === '' ) ? '' : absint( $posted_scheme[ 'subscription_trial_length' ] );
298
+            }
299
+
300
+            // Format subscription trial period.
301
+            $trial_periods = apply_filters( 'wcsatt_stt_trial_periods', array( 'day', 'week', 'month', 'year' ) );
302
+            if ( isset( $posted_scheme[ 'subscription_trial_period' ] ) && in_array( $posted_scheme[ 'subscription_trial_period' ], $trial_periods ) ) {
303
+                $posted_scheme[ 'subscription_trial_period' ] = trim( $posted_scheme[ 'subscription_trial_period' ] );
304
+            }
305
+
306
+            return $posted_scheme;
307
+        } // END wcsatt_stt_process_scheme_data()
308
+
309
+        /**
310
+         * Adds the additional subscription scheme data for products with attached subscription schemes.
311
+         *
312
+         * @param  object     $_product
313
+         * @param  array      $subscription_scheme
314
+         * @param  WC_Product $product
315
+         * @return string
316
+         */
317
+        public function add_sub_scheme_data_price_html( $_product, $subscription_scheme, $product ) {
318
+            if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) ) {
319
+                $_product->subscription_sign_up_fee = $subscription_scheme[ 'subscription_sign_up_fee' ];
320
+            }
321
+
322
+            if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) ) {
323
+                $_product->subscription_trial_length = $subscription_scheme[ 'subscription_trial_length' ];
324
+            }
325
+
326
+            if ( isset( $subscription_scheme[ 'subscription_trial_period' ] ) ) {
327
+                $_product->subscription_trial_period = $subscription_scheme[ 'subscription_trial_period' ];
328
+            }
329
+
330
+            return $_product;
331
+        } // END add_sub_scheme_data_price_html()
332
+
333
+        /**
334
+         * Adds the extra subscription scheme data to the product object.
335
+         * This allows the subscription price to change the initial and
336
+         * recurring subscriptions.
337
+         *
338
+         * @param  object $_cloned
339
+         * @param  array  $subscription_scheme
340
+         * @return object
341
+         */
342
+        public function sub_product_scheme_option( $_cloned, $subscription_scheme ) {
343
+            if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) && $subscription_scheme[ 'subscription_sign_up_fee' ] > 0 ) {
344
+                $_cloned->subscription_sign_up_fee = $subscription_scheme[ 'subscription_sign_up_fee' ];
345
+            }
346
+
347
+            if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) && 0 != $subscription_scheme[ 'subscription_trial_length' ] ) {
348
+                $_cloned->subscription_trial_length = $subscription_scheme[ 'subscription_trial_length' ];
349
+                $_cloned->subscription_trial_period = $subscription_scheme[ 'subscription_trial_period' ];
350
+            }
351
+
352
+            return $_cloned;
353
+        } // END sub_product_scheme_option()
354
+
355
+        /**
356
+         * Filters the price string to include the sign up fee and/or trial 
357
+         * to pass per subscription scheme option.
358
+         *
359
+         * @param  array $prices
360
+         * @param  array $subscription_scheme
361
+         * @return array
362
+         */
363
+        public function get_price_string( $prices, $subscription_scheme ) {
364
+            if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) && $subscription_scheme[ 'subscription_sign_up_fee' ] > 0 ) {
365
+                $prices[ 'sign_up_fee' ] = true;
366
+            }
367
+
368
+            if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) && 0 != $subscription_scheme[ 'subscription_trial_length' ] ) {
369
+                $prices[ 'trial_length' ] = true;
370
+            }
371
+
372
+            return $prices;
373
+        } // END get_price_string()
374
+
375
+        /**
376
+         * Filter the suffix price string.
377
+         *
378
+         * @param object     $_product
379
+         * @param array      $subscription_scheme
380
+         * @param WC_Product $product
381
+         * @return string
382
+         */
383
+        /*public function filter_suffix_price_html( $_product, $subscription_scheme, $product ) {
384 384
 			$subscription_string = '';
385 385
 
386 386
 			if ( isset( $_product->subscription_trial_length ) && 0 != $_product->subscription_trial_length ) {
@@ -403,97 +403,97 @@  discard block
 block discarded – undo
403 403
 			return $subscription_string;
404 404
 		}*/
405 405
 
406
-		/**
407
-		 * Converts a cart item if it's a subscription with 
408
-		 * a trial subscription or/and has a sign-up fee.
409
-		 *
410
-		 * @param  array $cart_item
411
-		 * @return array
412
-		 */
413
-		public function add_cart_item( $cart_item ) {
414
-			$active_scheme = WCS_ATT_Schemes::get_active_subscription_scheme( $cart_item );
415
-
416
-			if ( $active_scheme && $cart_item['data']->is_converted_to_sub == 'yes' ) {
417
-
418
-				$sign_up_fee  = $this->get_item_signup_fee( $cart_item[ 'product_id' ], $active_scheme );
419
-				$trial_length = $this->get_item_trial_length( $cart_item[ 'product_id' ], $active_scheme );
420
-				$trial_period = $this->get_item_trial_period( $cart_item[ 'product_id' ], $active_scheme );
421
-
422
-				// Subscription Price
423
-				$price = $cart_item['data']->subscription_price;
424
-
425
-				// Is there a sign up fee?
426
-				$sign_up_fee = ! empty( $sign_up_fee ) ? $sign_up_fee : '';
427
-
428
-				// If a trial length is more than zero then re-adjust the price.
429
-				if ( $trial_length > 0 ) {
430
-					$cart_item['data']->price = $sign_up_fee;
431
-					$cart_item['data']->subscription_price = $sign_up_fee;
432
-					$cart_item['data']->sale_price = $sign_up_fee;
433
-					$cart_item['data']->regular_price = $sign_up_fee;
434
-					$cart_item['data']->initial_amount = $sign_up_fee;
435
-					$cart_item['data']->subscription_sign_up_fee = $sign_up_fee;
436
-					$cart_item['data']->subscription_trial_length = $trial_length;
437
-					$cart_item['data']->subscription_trial_period = $trial_period;
438
-				} else {
439
-					$cart_item['data']->price = $price + $sign_up_fee;
440
-					$cart_item['data']->subscription_price = $price + $sign_up_fee;
441
-					$cart_item['data']->sale_price = $price + $sign_up_fee;
442
-					$cart_item['data']->regular_price = $price + $sign_up_fee;
443
-					$cart_item['data']->initial_amount = $price + $sign_up_fee;
444
-					$cart_item['data']->subscription_sign_up_fee = $sign_up_fee;
445
-					$cart_item['data']->subscription_trial_length = 0;
446
-					$cart_item['data']->subscription_trial_period = '';
447
-				}
448
-
449
-			}
450
-
451
-			return $cart_item;
452
-		} // END add_cart_item()
453
-
454
-		/**
455
-		 * Get the item signup fee from the subscription scheme.
456
-		 *
457
-		 * @param int  $product_id
458
-		 * @param int  $scheme_id
459
-		 * @return int
460
-		 */
461
-		public function get_item_signup_fee( $product_id, $scheme_id ) {
462
-			$product_schemes = get_post_meta( $product_id, '_wcsatt_schemes', true );
463
-			$thescheme = $product_schemes[$scheme_id];
464
-
465
-			return $thescheme['subscription_sign_up_fee'];
466
-		} // END get_item_signup_fee()
467
-
468
-		/**
469
-		 * Get the item trial length from the subscription scheme.
470
-		 *
471
-		 * @param int  $product_id
472
-		 * @param int  $scheme_id
473
-		 * @return int
474
-		 */
475
-		public function get_item_trial_length( $product_id, $scheme_id ) {
476
-			$product_schemes = get_post_meta( $product_id, '_wcsatt_schemes', true );
477
-			$thescheme = $product_schemes[$scheme_id];
478
-
479
-			return $thescheme['subscription_trial_length'];
480
-		} // END get_item_trial_length()
481
-
482
-		/**
483
-		 * Get the item trial period from the subscription scheme.
484
-		 *
485
-		 * @param  int    $product_id
486
-		 * @param  int    $scheme_id
487
-		 * @return string
488
-		 */
489
-		public function get_item_trial_period( $product_id, $scheme_id ) {
490
-			$product_schemes = get_post_meta( $product_id, '_wcsatt_schemes', true );
491
-			$thescheme = $product_schemes[$scheme_id];
492
-
493
-			return $thescheme['subscription_trial_period'];
494
-		} // END get_item_trial_period()
495
-
496
-	} // END class
406
+        /**
407
+         * Converts a cart item if it's a subscription with 
408
+         * a trial subscription or/and has a sign-up fee.
409
+         *
410
+         * @param  array $cart_item
411
+         * @return array
412
+         */
413
+        public function add_cart_item( $cart_item ) {
414
+            $active_scheme = WCS_ATT_Schemes::get_active_subscription_scheme( $cart_item );
415
+
416
+            if ( $active_scheme && $cart_item['data']->is_converted_to_sub == 'yes' ) {
417
+
418
+                $sign_up_fee  = $this->get_item_signup_fee( $cart_item[ 'product_id' ], $active_scheme );
419
+                $trial_length = $this->get_item_trial_length( $cart_item[ 'product_id' ], $active_scheme );
420
+                $trial_period = $this->get_item_trial_period( $cart_item[ 'product_id' ], $active_scheme );
421
+
422
+                // Subscription Price
423
+                $price = $cart_item['data']->subscription_price;
424
+
425
+                // Is there a sign up fee?
426
+                $sign_up_fee = ! empty( $sign_up_fee ) ? $sign_up_fee : '';
427
+
428
+                // If a trial length is more than zero then re-adjust the price.
429
+                if ( $trial_length > 0 ) {
430
+                    $cart_item['data']->price = $sign_up_fee;
431
+                    $cart_item['data']->subscription_price = $sign_up_fee;
432
+                    $cart_item['data']->sale_price = $sign_up_fee;
433
+                    $cart_item['data']->regular_price = $sign_up_fee;
434
+                    $cart_item['data']->initial_amount = $sign_up_fee;
435
+                    $cart_item['data']->subscription_sign_up_fee = $sign_up_fee;
436
+                    $cart_item['data']->subscription_trial_length = $trial_length;
437
+                    $cart_item['data']->subscription_trial_period = $trial_period;
438
+                } else {
439
+                    $cart_item['data']->price = $price + $sign_up_fee;
440
+                    $cart_item['data']->subscription_price = $price + $sign_up_fee;
441
+                    $cart_item['data']->sale_price = $price + $sign_up_fee;
442
+                    $cart_item['data']->regular_price = $price + $sign_up_fee;
443
+                    $cart_item['data']->initial_amount = $price + $sign_up_fee;
444
+                    $cart_item['data']->subscription_sign_up_fee = $sign_up_fee;
445
+                    $cart_item['data']->subscription_trial_length = 0;
446
+                    $cart_item['data']->subscription_trial_period = '';
447
+                }
448
+
449
+            }
450
+
451
+            return $cart_item;
452
+        } // END add_cart_item()
453
+
454
+        /**
455
+         * Get the item signup fee from the subscription scheme.
456
+         *
457
+         * @param int  $product_id
458
+         * @param int  $scheme_id
459
+         * @return int
460
+         */
461
+        public function get_item_signup_fee( $product_id, $scheme_id ) {
462
+            $product_schemes = get_post_meta( $product_id, '_wcsatt_schemes', true );
463
+            $thescheme = $product_schemes[$scheme_id];
464
+
465
+            return $thescheme['subscription_sign_up_fee'];
466
+        } // END get_item_signup_fee()
467
+
468
+        /**
469
+         * Get the item trial length from the subscription scheme.
470
+         *
471
+         * @param int  $product_id
472
+         * @param int  $scheme_id
473
+         * @return int
474
+         */
475
+        public function get_item_trial_length( $product_id, $scheme_id ) {
476
+            $product_schemes = get_post_meta( $product_id, '_wcsatt_schemes', true );
477
+            $thescheme = $product_schemes[$scheme_id];
478
+
479
+            return $thescheme['subscription_trial_length'];
480
+        } // END get_item_trial_length()
481
+
482
+        /**
483
+         * Get the item trial period from the subscription scheme.
484
+         *
485
+         * @param  int    $product_id
486
+         * @param  int    $scheme_id
487
+         * @return string
488
+         */
489
+        public function get_item_trial_period( $product_id, $scheme_id ) {
490
+            $product_schemes = get_post_meta( $product_id, '_wcsatt_schemes', true );
491
+            $thescheme = $product_schemes[$scheme_id];
492
+
493
+            return $thescheme['subscription_trial_period'];
494
+        } // END get_item_trial_period()
495
+
496
+    } // END class
497 497
 
498 498
 } // END if class exists
499 499
 
Please login to merge, or discard this patch.
Spacing   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -17,9 +17,9 @@  discard block
 block discarded – undo
17 17
  * License: GNU General Public License v3.0
18 18
  * License URI: http://www.gnu.org/licenses/gpl-3.0.html
19 19
  */
20
-if ( ! defined('ABSPATH') ) exit; // Exit if accessed directly.
20
+if (!defined('ABSPATH')) exit; // Exit if accessed directly.
21 21
 
22
-if ( ! class_exists( 'WCSATT_STT' ) ) {
22
+if (!class_exists('WCSATT_STT')) {
23 23
 	class WCSATT_STT {
24 24
 
25 25
 		/* Plugin version. */
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 		 * @since 1.0.0
53 53
 		 */
54 54
 		public static function instance() {
55
-			if ( is_null( self::$_instance ) ) {
55
+			if (is_null(self::$_instance)) {
56 56
 				self::$_instance = new self();
57 57
 			}
58 58
 			return self::$_instance;
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		 * @since 1.0.0
65 65
 		 */
66 66
 		public function __clone() {
67
-			_doing_it_wrong( __FUNCTION__, __( 'Foul!' ), '1.0.0' );
67
+			_doing_it_wrong(__FUNCTION__, __('Foul!'), '1.0.0');
68 68
 		}
69 69
 
70 70
 		/**
@@ -73,21 +73,21 @@  discard block
 block discarded – undo
73 73
 		 * @since 1.0.0
74 74
 		 */
75 75
 		public function __wakeup() {
76
-			_doing_it_wrong( __FUNCTION__, __( 'Foul!' ), '1.0.0' );
76
+			_doing_it_wrong(__FUNCTION__, __('Foul!'), '1.0.0');
77 77
 		}
78 78
 
79 79
 		/**
80 80
 		 * Load the plugin.
81 81
 		 */
82 82
 		public function __construct() {
83
-			add_action( 'plugins_loaded', array( $this, 'load_plugin' ) );
84
-			add_action( 'init', array( $this, 'init_plugin' ) );
85
-			add_action( 'admin_init', array( $this, 'admin_wcsatt_stt_product_meta' ) );
86
-			add_filter( 'plugin_row_meta', array( $this, 'plugin_meta_links' ), 10, 4 );
83
+			add_action('plugins_loaded', array($this, 'load_plugin'));
84
+			add_action('init', array($this, 'init_plugin'));
85
+			add_action('admin_init', array($this, 'admin_wcsatt_stt_product_meta'));
86
+			add_filter('plugin_row_meta', array($this, 'plugin_meta_links'), 10, 4);
87 87
 		}
88 88
 
89 89
 		public function plugin_path() {
90
-			return untrailingslashit( plugin_dir_path( __FILE__ ) );
90
+			return untrailingslashit(plugin_dir_path(__FILE__));
91 91
 		} // END plugin_path()
92 92
 
93 93
 		/*
@@ -97,14 +97,14 @@  discard block
 block discarded – undo
97 97
 			global $woocommerce;
98 98
 
99 99
 			// Check that the required WooCommerce is running.
100
-			if ( version_compare( $woocommerce->version, self::REQ_WC_VERSION, '<' ) ) {
101
-				add_action( 'admin_notices', array( $this, 'wcsatt_stt_wc_admin_notice' ) );
100
+			if (version_compare($woocommerce->version, self::REQ_WC_VERSION, '<')) {
101
+				add_action('admin_notices', array($this, 'wcsatt_stt_wc_admin_notice'));
102 102
 				return false;
103 103
 			}
104 104
 
105 105
 			// Checks that WooCommerce Subscribe All the Things is running or is less than the required version.
106
-			if ( ! class_exists( 'WCS_ATT' ) || version_compare( WCS_ATT::VERSION, self::REQ_WCSATT_VERSION, '<' ) ) {
107
-				add_action( 'admin_notices', array( $this, 'wcsatt_stt_admin_notice' ) );
106
+			if (!class_exists('WCS_ATT') || version_compare(WCS_ATT::VERSION, self::REQ_WCSATT_VERSION, '<')) {
107
+				add_action('admin_notices', array($this, 'wcsatt_stt_admin_notice'));
108 108
 				return false;
109 109
 			}
110 110
 		} // END load_plugin()
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 		 * @return void
116 116
 		 */
117 117
 		public function wcsatt_stt_wc_admin_notice() {
118
-			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' ), 'Sign up and Trial Options Add-on for WCSATT', 'WooCommerce', self::REQ_WC_VERSION ) . '</p></div>';
118
+			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'), 'Sign up and Trial Options Add-on for WCSATT', 'WooCommerce', self::REQ_WC_VERSION).'</p></div>';
119 119
 		} // END wcsatt_stt_wc_admin_notice()
120 120
 
121 121
 		/**
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 		 * @return void
125 125
 		 */
126 126
 		public function wcsatt_stt_admin_notice() {
127
-			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' ), 'Sign up and Trial Options Add-on', 'WooCommerce Subscribe to All the Things', self::REQ_WCSATT_VERSION ) . '</p></div>';
127
+			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'), 'Sign up and Trial Options Add-on', 'WooCommerce Subscribe to All the Things', self::REQ_WCSATT_VERSION).'</p></div>';
128 128
 		} // END wcsatt_stt_admin_notice()
129 129
 
130 130
 		/**
@@ -134,22 +134,22 @@  discard block
 block discarded – undo
134 134
 		 */
135 135
 		public function init_plugin() {
136 136
 			// Load text domain.
137
-			load_plugin_textdomain( 'wc-satt-stt', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
137
+			load_plugin_textdomain('wc-satt-stt', false, dirname(plugin_basename(__FILE__)).'/languages/');
138 138
 
139 139
 			// Adds the sign up fee and trial data to the price html on the 'wcsatt_overridden_subscription_prices_product' filter.
140
-			add_filter( 'wcsatt_overridden_subscription_prices_product', array( $this, 'add_sub_scheme_data_price_html' ), 10, 3 );
140
+			add_filter('wcsatt_overridden_subscription_prices_product', array($this, 'add_sub_scheme_data_price_html'), 10, 3);
141 141
 
142 142
 			// Adds the extra subscription scheme data to the product object.
143
-			add_filter( 'wcsatt_sub_product_scheme_option', array( $this, 'sub_product_scheme_option' ), 10, 2 );
143
+			add_filter('wcsatt_sub_product_scheme_option', array($this, 'sub_product_scheme_option'), 10, 2);
144 144
 
145 145
 			// Filters the price string to include the sign up fee and/or trial to pass per scheme option.
146
-			add_filter( 'wcsatt_get_single_product_price_string', array( $this, 'get_price_string' ), 10, 2 );
146
+			add_filter('wcsatt_get_single_product_price_string', array($this, 'get_price_string'), 10, 2);
147 147
 
148 148
 			// Filters the suffix price html on the 'wcsatt_suffix_price_html' filter.
149 149
 			//add_filter( 'wcsatt_suffix_price_html', array( $this, 'filter_suffix_price_html' ), 10, 1 );
150 150
 
151 151
 			// Overrides the price of the subscription for sign up fee and/or trial on the 'woocommerce_add_cart_item' filter.
152
-			add_filter( 'woocommerce_add_cart_item', array( $this, 'add_cart_item' ), 15, 1 );
152
+			add_filter('woocommerce_add_cart_item', array($this, 'add_cart_item'), 15, 1);
153 153
 		} // END init_plugin()
154 154
 
155 155
 		/**
@@ -162,10 +162,10 @@  discard block
 block discarded – undo
162 162
 			//add_action( 'wcsatt_subscription_scheme_content', array( $this, 'wcsatt_stt_fields' ), 15, 3 );
163 163
 
164 164
 			// Subscription scheme options displayed on the 'wcsatt_subscription_scheme_product_content' action.
165
-			add_action( 'wcsatt_subscription_scheme_product_content', array( $this, 'wcsatt_stt_fields' ), 15, 3 );
165
+			add_action('wcsatt_subscription_scheme_product_content', array($this, 'wcsatt_stt_fields'), 15, 3);
166 166
 
167 167
 			// Filter the subscription scheme data to process the sign up and trial options on the ''wcsatt_subscription_scheme_process_scheme_data' filter.
168
-			add_filter( 'wcsatt_subscription_scheme_process_scheme_data', array( $this, 'wcsatt_stt_process_scheme_data' ), 10, 2 );
168
+			add_filter('wcsatt_subscription_scheme_process_scheme_data', array($this, 'wcsatt_stt_process_scheme_data'), 10, 2);
169 169
 		} // END admin_wcsatt_stt_product_meta()
170 170
 
171 171
 		/**
@@ -175,10 +175,10 @@  discard block
 block discarded – undo
175 175
 		 * @param mixed $file  Plugin Base file
176 176
 		 * @return array
177 177
 		 */
178
-		public function plugin_meta_links( $links, $file, $data, $status ) {
179
-			if ( $file == plugin_basename( __FILE__ ) ) {
180
-				$author1 = '<a href="' . $data[ 'AuthorURI' ] . '">' . $data[ 'Author' ] . '</a>';
181
-				$links[ 1 ] = sprintf( __( 'By %s', WCSATT_STT::TEXT_DOMAIN ), $author1 );
178
+		public function plugin_meta_links($links, $file, $data, $status) {
179
+			if ($file == plugin_basename(__FILE__)) {
180
+				$author1 = '<a href="'.$data['AuthorURI'].'">'.$data['Author'].'</a>';
181
+				$links[1] = sprintf(__('By %s', WCSATT_STT::TEXT_DOMAIN), $author1);
182 182
 			}
183 183
 
184 184
 			return $links;
@@ -190,14 +190,14 @@  discard block
 block discarded – undo
190 190
 		 * @param  array $defaults
191 191
 		 * @return void
192 192
 		 */
193
-		public static function add_default_subscription_schemes_content( $defaults ) {
193
+		public static function add_default_subscription_schemes_content($defaults) {
194 194
 			$new_defaults = array(
195 195
 				'subscription_sign_up_fee'  => '',
196 196
 				'subscription_trial_length' => '',
197 197
 				'subscription_trial_period' => ''
198 198
 			);
199 199
 
200
-			return array_merge( $new_defaults, $defaults );
200
+			return array_merge($new_defaults, $defaults);
201 201
 		} // END add_default_subscription_schemes_content()
202 202
 
203 203
 		/**
@@ -208,11 +208,11 @@  discard block
 block discarded – undo
208 208
 		 * @param  int   $post_id
209 209
 		 * @return void
210 210
 		 */
211
-		public function wcsatt_stt_fields( $index, $scheme_data, $post_id ) {
212
-			if ( ! empty( $scheme_data ) ) {
213
-				$subscription_sign_up_fee = ! empty( $scheme_data[ 'subscription_sign_up_fee' ] ) ? $scheme_data[ 'subscription_sign_up_fee' ] : '';
214
-				$subscription_trial_length = isset( $scheme_data[ 'subscription_trial_length' ] ) ? $scheme_data[ 'subscription_trial_length' ] : 0;
215
-				$subscription_trial_period = isset( $scheme_data[ 'subscription_trial_period' ] ) ? $scheme_data[ 'subscription_trial_period' ] : '';
211
+		public function wcsatt_stt_fields($index, $scheme_data, $post_id) {
212
+			if (!empty($scheme_data)) {
213
+				$subscription_sign_up_fee = !empty($scheme_data['subscription_sign_up_fee']) ? $scheme_data['subscription_sign_up_fee'] : '';
214
+				$subscription_trial_length = isset($scheme_data['subscription_trial_length']) ? $scheme_data['subscription_trial_length'] : 0;
215
+				$subscription_trial_period = isset($scheme_data['subscription_trial_period']) ? $scheme_data['subscription_trial_period'] : '';
216 216
 			} else {
217 217
 				$subscription_sign_up_fee = '';
218 218
 				$subscription_trial_length = 0;
@@ -220,45 +220,45 @@  discard block
 block discarded – undo
220 220
 			}
221 221
 
222 222
 			// Sign-up Fee
223
-			woocommerce_wp_text_input( array(
223
+			woocommerce_wp_text_input(array(
224 224
 				'id'          => '_subscription_sign_up_fee',
225 225
 				'class'       => 'wc_input_subscription_intial_price',
226 226
 				// translators: %s is a currency symbol / code
227
-				'label'       => sprintf( __( 'Sign-up Fee (%s)', WCSATT_STT::TEXT_DOMAIN ), get_woocommerce_currency_symbol() ),
228
-				'placeholder' => _x( 'e.g. 9.90', 'example price', WCSATT_STT::TEXT_DOMAIN ),
229
-				'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 ),
227
+				'label'       => sprintf(__('Sign-up Fee (%s)', WCSATT_STT::TEXT_DOMAIN), get_woocommerce_currency_symbol()),
228
+				'placeholder' => _x('e.g. 9.90', 'example price', WCSATT_STT::TEXT_DOMAIN),
229
+				'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),
230 230
 				'desc_tip'    => true,
231 231
 				'type'        => 'text',
232 232
 				'custom_attributes' => array(
233 233
 					'step' => 'any',
234 234
 					'min'  => '0',
235 235
 				),
236
-				'name'        => 'wcsatt_schemes[' . $index . '][subscription_sign_up_fee]',
236
+				'name'        => 'wcsatt_schemes['.$index.'][subscription_sign_up_fee]',
237 237
 				'value'       => $subscription_sign_up_fee
238
-			) );
238
+			));
239 239
 
240 240
 			// Trial Length
241
-			woocommerce_wp_text_input( array(
241
+			woocommerce_wp_text_input(array(
242 242
 				'id'          => '_subscription_trial_length',
243 243
 				'class'       => 'wc_input_subscription_trial_length',
244
-				'label'       => __( 'Free Trial', WCSATT_STT::TEXT_DOMAIN ),
245
-				'name'        => 'wcsatt_schemes[' . $index . '][subscription_trial_length]',
244
+				'label'       => __('Free Trial', WCSATT_STT::TEXT_DOMAIN),
245
+				'name'        => 'wcsatt_schemes['.$index.'][subscription_trial_length]',
246 246
 				'value'       => $subscription_trial_length
247
-			) );
247
+			));
248 248
 
249 249
 			// Trial Period
250
-			woocommerce_wp_select( array(
250
+			woocommerce_wp_select(array(
251 251
 				'id'          => '_subscription_trial_period',
252 252
 				'class'       => 'wc_input_subscription_trial_period',
253
-				'label'       => __( 'Subscription Trial Period', WCSATT_STT::TEXT_DOMAIN ),
253
+				'label'       => __('Subscription Trial Period', WCSATT_STT::TEXT_DOMAIN),
254 254
 				'options'     => wcs_get_available_time_periods(),
255 255
 				// translators: placeholder is trial period validation message if passed an invalid value (e.g. "Trial period can not exceed 4 weeks")
256
-				'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() ),
256
+				'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()),
257 257
 				'desc_tip'    => true,
258
-				'value'       => WC_Subscriptions_Product::get_trial_period( $post_id ), // Explicitly set value in to ensure backward compatibility
259
-				'name'        => 'wcsatt_schemes[' . $index . '][subscription_trial_period]',
258
+				'value'       => WC_Subscriptions_Product::get_trial_period($post_id), // Explicitly set value in to ensure backward compatibility
259
+				'name'        => 'wcsatt_schemes['.$index.'][subscription_trial_period]',
260 260
 				'value'       => $subscription_trial_period
261
-		) );
261
+		));
262 262
 		} // END wcsatt_stt_fields()
263 263
 
264 264
 		/**
@@ -269,38 +269,38 @@  discard block
 block discarded – undo
269 269
 		 * @param  string $product_type
270 270
 		 * @return void
271 271
 		 */
272
-		public function wcsatt_stt_process_scheme_data( $posted_scheme, $product_type ) {
272
+		public function wcsatt_stt_process_scheme_data($posted_scheme, $product_type) {
273 273
 			// Copy variable type fields.
274
-			if ( 'variable' == $product_type ) {
275
-				if ( isset( $posted_scheme[ 'subscription_sign_up_fee_variable' ] ) ) {
276
-					$posted_scheme[ 'subscription_sign_up_fee' ] = $posted_scheme[ 'subscription_sign_up_fee_variable' ];
274
+			if ('variable' == $product_type) {
275
+				if (isset($posted_scheme['subscription_sign_up_fee_variable'])) {
276
+					$posted_scheme['subscription_sign_up_fee'] = $posted_scheme['subscription_sign_up_fee_variable'];
277 277
 				}
278
-				if ( isset( $posted_scheme[ 'subscription_trial_length_variable' ] ) ) {
279
-					$posted_scheme[ 'subscription_trial_length' ] = $posted_scheme[ 'subscription_trial_length_variable' ];
278
+				if (isset($posted_scheme['subscription_trial_length_variable'])) {
279
+					$posted_scheme['subscription_trial_length'] = $posted_scheme['subscription_trial_length_variable'];
280 280
 				}
281
-				if ( isset( $posted_scheme[ 'subscription_trial_period_variable' ] ) ) {
282
-					$posted_scheme[ 'subscription_trial_period' ] = $posted_scheme[ 'subscription_trial_period_variable'];
281
+				if (isset($posted_scheme['subscription_trial_period_variable'])) {
282
+					$posted_scheme['subscription_trial_period'] = $posted_scheme['subscription_trial_period_variable'];
283 283
 				}
284 284
 			}
285 285
 
286 286
 			// Format subscription sign up fee.
287
-			if ( isset( $posted_scheme[ 'subscription_sign_up_fee' ] ) ) {
288
-				$posted_scheme[ 'subscription_sign_up_fee' ] = ( $posted_scheme[ 'subscription_sign_up_fee' ] === '' ) ? '' : wc_format_decimal( $posted_scheme[ 'subscription_sign_up_fee' ] );
287
+			if (isset($posted_scheme['subscription_sign_up_fee'])) {
288
+				$posted_scheme['subscription_sign_up_fee'] = ($posted_scheme['subscription_sign_up_fee'] === '') ? '' : wc_format_decimal($posted_scheme['subscription_sign_up_fee']);
289 289
 			}
290 290
 
291 291
 			// Make sure trial period is within allowable range.
292 292
 			$subscription_ranges = wcs_get_subscription_ranges();
293
-			$max_trial_length = count( $subscription_ranges[ $posted_scheme[ 'subscription_trial_period' ] ] ) - 1;
293
+			$max_trial_length = count($subscription_ranges[$posted_scheme['subscription_trial_period']]) - 1;
294 294
 
295 295
 			// Format subscription trial length.
296
-			if ( isset( $posted_scheme[ 'subscription_trial_length' ] ) && $posted_scheme[ 'subscription_trial_length' ] > $max_trial_length ) {
297
-				$posted_scheme[ 'subscription_trial_length' ] = ( $posted_scheme[ 'subscription_trial_length' ] === '' ) ? '' : absint( $posted_scheme[ 'subscription_trial_length' ] );
296
+			if (isset($posted_scheme['subscription_trial_length']) && $posted_scheme['subscription_trial_length'] > $max_trial_length) {
297
+				$posted_scheme['subscription_trial_length'] = ($posted_scheme['subscription_trial_length'] === '') ? '' : absint($posted_scheme['subscription_trial_length']);
298 298
 			}
299 299
 
300 300
 			// Format subscription trial period.
301
-			$trial_periods = apply_filters( 'wcsatt_stt_trial_periods', array( 'day', 'week', 'month', 'year' ) );
302
-			if ( isset( $posted_scheme[ 'subscription_trial_period' ] ) && in_array( $posted_scheme[ 'subscription_trial_period' ], $trial_periods ) ) {
303
-				$posted_scheme[ 'subscription_trial_period' ] = trim( $posted_scheme[ 'subscription_trial_period' ] );
301
+			$trial_periods = apply_filters('wcsatt_stt_trial_periods', array('day', 'week', 'month', 'year'));
302
+			if (isset($posted_scheme['subscription_trial_period']) && in_array($posted_scheme['subscription_trial_period'], $trial_periods)) {
303
+				$posted_scheme['subscription_trial_period'] = trim($posted_scheme['subscription_trial_period']);
304 304
 			}
305 305
 
306 306
 			return $posted_scheme;
@@ -314,17 +314,17 @@  discard block
 block discarded – undo
314 314
 		 * @param  WC_Product $product
315 315
 		 * @return string
316 316
 		 */
317
-		public function add_sub_scheme_data_price_html( $_product, $subscription_scheme, $product ) {
318
-			if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) ) {
319
-				$_product->subscription_sign_up_fee = $subscription_scheme[ 'subscription_sign_up_fee' ];
317
+		public function add_sub_scheme_data_price_html($_product, $subscription_scheme, $product) {
318
+			if (isset($subscription_scheme['subscription_sign_up_fee'])) {
319
+				$_product->subscription_sign_up_fee = $subscription_scheme['subscription_sign_up_fee'];
320 320
 			}
321 321
 
322
-			if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) ) {
323
-				$_product->subscription_trial_length = $subscription_scheme[ 'subscription_trial_length' ];
322
+			if (isset($subscription_scheme['subscription_trial_length'])) {
323
+				$_product->subscription_trial_length = $subscription_scheme['subscription_trial_length'];
324 324
 			}
325 325
 
326
-			if ( isset( $subscription_scheme[ 'subscription_trial_period' ] ) ) {
327
-				$_product->subscription_trial_period = $subscription_scheme[ 'subscription_trial_period' ];
326
+			if (isset($subscription_scheme['subscription_trial_period'])) {
327
+				$_product->subscription_trial_period = $subscription_scheme['subscription_trial_period'];
328 328
 			}
329 329
 
330 330
 			return $_product;
@@ -339,14 +339,14 @@  discard block
 block discarded – undo
339 339
 		 * @param  array  $subscription_scheme
340 340
 		 * @return object
341 341
 		 */
342
-		public function sub_product_scheme_option( $_cloned, $subscription_scheme ) {
343
-			if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) && $subscription_scheme[ 'subscription_sign_up_fee' ] > 0 ) {
344
-				$_cloned->subscription_sign_up_fee = $subscription_scheme[ 'subscription_sign_up_fee' ];
342
+		public function sub_product_scheme_option($_cloned, $subscription_scheme) {
343
+			if (isset($subscription_scheme['subscription_sign_up_fee']) && $subscription_scheme['subscription_sign_up_fee'] > 0) {
344
+				$_cloned->subscription_sign_up_fee = $subscription_scheme['subscription_sign_up_fee'];
345 345
 			}
346 346
 
347
-			if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) && 0 != $subscription_scheme[ 'subscription_trial_length' ] ) {
348
-				$_cloned->subscription_trial_length = $subscription_scheme[ 'subscription_trial_length' ];
349
-				$_cloned->subscription_trial_period = $subscription_scheme[ 'subscription_trial_period' ];
347
+			if (isset($subscription_scheme['subscription_trial_length']) && 0 != $subscription_scheme['subscription_trial_length']) {
348
+				$_cloned->subscription_trial_length = $subscription_scheme['subscription_trial_length'];
349
+				$_cloned->subscription_trial_period = $subscription_scheme['subscription_trial_period'];
350 350
 			}
351 351
 
352 352
 			return $_cloned;
@@ -360,13 +360,13 @@  discard block
 block discarded – undo
360 360
 		 * @param  array $subscription_scheme
361 361
 		 * @return array
362 362
 		 */
363
-		public function get_price_string( $prices, $subscription_scheme ) {
364
-			if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) && $subscription_scheme[ 'subscription_sign_up_fee' ] > 0 ) {
365
-				$prices[ 'sign_up_fee' ] = true;
363
+		public function get_price_string($prices, $subscription_scheme) {
364
+			if (isset($subscription_scheme['subscription_sign_up_fee']) && $subscription_scheme['subscription_sign_up_fee'] > 0) {
365
+				$prices['sign_up_fee'] = true;
366 366
 			}
367 367
 
368
-			if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) && 0 != $subscription_scheme[ 'subscription_trial_length' ] ) {
369
-				$prices[ 'trial_length' ] = true;
368
+			if (isset($subscription_scheme['subscription_trial_length']) && 0 != $subscription_scheme['subscription_trial_length']) {
369
+				$prices['trial_length'] = true;
370 370
 			}
371 371
 
372 372
 			return $prices;
@@ -410,23 +410,23 @@  discard block
 block discarded – undo
410 410
 		 * @param  array $cart_item
411 411
 		 * @return array
412 412
 		 */
413
-		public function add_cart_item( $cart_item ) {
414
-			$active_scheme = WCS_ATT_Schemes::get_active_subscription_scheme( $cart_item );
413
+		public function add_cart_item($cart_item) {
414
+			$active_scheme = WCS_ATT_Schemes::get_active_subscription_scheme($cart_item);
415 415
 
416
-			if ( $active_scheme && $cart_item['data']->is_converted_to_sub == 'yes' ) {
416
+			if ($active_scheme && $cart_item['data']->is_converted_to_sub == 'yes') {
417 417
 
418
-				$sign_up_fee  = $this->get_item_signup_fee( $cart_item[ 'product_id' ], $active_scheme );
419
-				$trial_length = $this->get_item_trial_length( $cart_item[ 'product_id' ], $active_scheme );
420
-				$trial_period = $this->get_item_trial_period( $cart_item[ 'product_id' ], $active_scheme );
418
+				$sign_up_fee  = $this->get_item_signup_fee($cart_item['product_id'], $active_scheme);
419
+				$trial_length = $this->get_item_trial_length($cart_item['product_id'], $active_scheme);
420
+				$trial_period = $this->get_item_trial_period($cart_item['product_id'], $active_scheme);
421 421
 
422 422
 				// Subscription Price
423 423
 				$price = $cart_item['data']->subscription_price;
424 424
 
425 425
 				// Is there a sign up fee?
426
-				$sign_up_fee = ! empty( $sign_up_fee ) ? $sign_up_fee : '';
426
+				$sign_up_fee = !empty($sign_up_fee) ? $sign_up_fee : '';
427 427
 
428 428
 				// If a trial length is more than zero then re-adjust the price.
429
-				if ( $trial_length > 0 ) {
429
+				if ($trial_length > 0) {
430 430
 					$cart_item['data']->price = $sign_up_fee;
431 431
 					$cart_item['data']->subscription_price = $sign_up_fee;
432 432
 					$cart_item['data']->sale_price = $sign_up_fee;
@@ -458,8 +458,8 @@  discard block
 block discarded – undo
458 458
 		 * @param int  $scheme_id
459 459
 		 * @return int
460 460
 		 */
461
-		public function get_item_signup_fee( $product_id, $scheme_id ) {
462
-			$product_schemes = get_post_meta( $product_id, '_wcsatt_schemes', true );
461
+		public function get_item_signup_fee($product_id, $scheme_id) {
462
+			$product_schemes = get_post_meta($product_id, '_wcsatt_schemes', true);
463 463
 			$thescheme = $product_schemes[$scheme_id];
464 464
 
465 465
 			return $thescheme['subscription_sign_up_fee'];
@@ -472,8 +472,8 @@  discard block
 block discarded – undo
472 472
 		 * @param int  $scheme_id
473 473
 		 * @return int
474 474
 		 */
475
-		public function get_item_trial_length( $product_id, $scheme_id ) {
476
-			$product_schemes = get_post_meta( $product_id, '_wcsatt_schemes', true );
475
+		public function get_item_trial_length($product_id, $scheme_id) {
476
+			$product_schemes = get_post_meta($product_id, '_wcsatt_schemes', true);
477 477
 			$thescheme = $product_schemes[$scheme_id];
478 478
 
479 479
 			return $thescheme['subscription_trial_length'];
@@ -486,8 +486,8 @@  discard block
 block discarded – undo
486 486
 		 * @param  int    $scheme_id
487 487
 		 * @return string
488 488
 		 */
489
-		public function get_item_trial_period( $product_id, $scheme_id ) {
490
-			$product_schemes = get_post_meta( $product_id, '_wcsatt_schemes', true );
489
+		public function get_item_trial_period($product_id, $scheme_id) {
490
+			$product_schemes = get_post_meta($product_id, '_wcsatt_schemes', true);
491 491
 			$thescheme = $product_schemes[$scheme_id];
492 492
 
493 493
 			return $thescheme['subscription_trial_period'];
Please login to merge, or discard this patch.