Completed
Push — master ( 5ead7b...3567a2 )
by Sébastien
02:56
created

WCSATT_STT::wcsatt_stt_process_scheme_data()   D

Complexity

Conditions 12
Paths 162

Size

Total Lines 36
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 36
rs 4.8484
cc 12
eloc 18
nc 162
nop 2

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * Plugin Name: WooCommerce Subscribe to All the Things - Sign up and Trial Addon
4
 * Plugin URI:  https://sebastiendumont.com
5
 * Version:     1.0.0 Alpha
6
 * Description: Add a sign up fee and free trial for each subscription scheme. Requires WooCommerce Subscribe to All the Things extension v1.1.1+.
7
 * Author:      Sebastien Dumont
8
 * Author URI:  https://sebastiendumont.com
9
 *
10
 * Text Domain: wc-satt-stt
11
 * Domain Path: /languages/
12
 *
13
 * Requires at least: 4.1
14
 * Tested up to: 4.5.2
15
 *
16
 * Copyright: © 2016 Sebastien Dumont
17
 * License: GNU General Public License v3.0
18
 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
19
 */
20
if ( ! defined('ABSPATH') ) exit; // Exit if accessed directly.
21
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
		/*
94
		 * Check requirements on activation.
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 on the 'wcsatt_sub_product_scheme_option' filter.
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 on the 'wcsatt_get_single_product_price_string' filter.
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 );
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
150
151
			// Adds the sign-up and/or trial data to the subscription scheme prices on the 'wcsatt_subscription_scheme_prices' filter.
152
			add_filter( 'wcsatt_subscription_scheme_prices', array( $this, 'add_subscription_scheme_prices' ), 10, 2 );
153
154
			// Overrides the price of the subscription for sign up fee and/or trial on the 'wcsatt_cart_item' filter.
155
			add_filter( 'wcsatt_cart_item', array( $this, 'update_cart_item_sub_data' ), 10, 1 );
156
		} // END init_plugin()
157
158
		/**
159
		 * Register the product meta data fields.
160
		 *
161
		 * @return void
162
		 */
163
		public function admin_wcsatt_stt_product_meta() {
164
			// Subscription scheme options displayed on the 'wcsatt_subscription_scheme_content' action.
165
			//add_action( 'wcsatt_subscription_scheme_content', array( $this, 'wcsatt_stt_fields' ), 15, 3 );
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
166
167
			// Subscription scheme options displayed on the 'wcsatt_subscription_scheme_product_content' action.
168
			add_action( 'wcsatt_subscription_scheme_product_content', array( $this, 'wcsatt_stt_fields' ), 15, 3 );
169
170
			// Filter the subscription scheme data to process the sign up and trial options on the ''wcsatt_subscription_scheme_process_scheme_data' filter.
171
			add_filter( 'wcsatt_subscription_scheme_process_scheme_data', array( $this, 'wcsatt_stt_process_scheme_data' ), 10, 2 );
172
		} // END admin_wcsatt_stt_product_meta()
173
174
		/**
175
		 * Show row meta on the plugin screen.
176
		 *
177
		 * @param mixed $links Plugin Row Meta
178
		 * @param mixed $file  Plugin Base file
179
		 * @return array
180
		 */
181
		public function plugin_meta_links( $links, $file, $data, $status ) {
182
			if ( $file == plugin_basename( __FILE__ ) ) {
183
				$author1 = '<a href="' . $data[ 'AuthorURI' ] . '">' . $data[ 'Author' ] . '</a>';
184
				$links[ 1 ] = sprintf( __( 'By %s', WCSATT_STT::TEXT_DOMAIN ), $author1 );
185
			}
186
187
			return $links;
188
		} // END plugin_meta_links()
189
190
		/**
191
		 * Adds the default values for subscriptions schemes content.
192
		 *
193
		 * @param  array $defaults
194
		 * @return void
195
		 */
196
		public static function add_default_subscription_schemes_content( $defaults ) {
197
			$new_defaults = array(
198
				'subscription_sign_up_fee'  => '',
199
				'subscription_trial_length' => '',
200
				'subscription_trial_period' => ''
201
			);
202
203
			return array_merge( $new_defaults, $defaults );
204
		} // END add_default_subscription_schemes_content()
205
206
		/**
207
		 * Adds the trial and sign up fields under the subscription section.
208
		 *
209
		 * @param  int   $index
210
		 * @param  array $scheme_data
211
		 * @param  int   $post_id
212
		 * @return void
213
		 */
214
		public function wcsatt_stt_fields( $index, $scheme_data, $post_id ) {
215
			if ( ! empty( $scheme_data ) ) {
216
				$subscription_sign_up_fee = ! empty( $scheme_data[ 'subscription_sign_up_fee' ] ) ? $scheme_data[ 'subscription_sign_up_fee' ] : '';
217
				$subscription_trial_length = isset( $scheme_data[ 'subscription_trial_length' ] ) ? $scheme_data[ 'subscription_trial_length' ] : 0;
218
				$subscription_trial_period = isset( $scheme_data[ 'subscription_trial_period' ] ) ? $scheme_data[ 'subscription_trial_period' ] : '';
219
			} else {
220
				$subscription_sign_up_fee = '';
221
				$subscription_trial_length = 0;
222
				$subscription_trial_period = '';
223
			}
224
225
			// Sign-up Fee
226
			woocommerce_wp_text_input( array(
227
				'id'          => '_subscription_sign_up_fee',
228
				'class'       => 'wc_input_subscription_intial_price',
229
				// translators: %s is a currency symbol / code
230
				'label'       => sprintf( __( 'Sign-up Fee (%s)', WCSATT_STT::TEXT_DOMAIN ), get_woocommerce_currency_symbol() ),
231
				'placeholder' => _x( 'e.g. 9.90', 'example price', WCSATT_STT::TEXT_DOMAIN ),
232
				'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 ),
233
				'desc_tip'    => true,
234
				'type'        => 'text',
235
				'custom_attributes' => array(
236
					'step' => 'any',
237
					'min'  => '0',
238
				),
239
				'name'        => 'wcsatt_schemes[' . $index . '][subscription_sign_up_fee]',
240
				'value'       => $subscription_sign_up_fee
241
			) );
242
243
			// Trial Length
244
			woocommerce_wp_text_input( array(
245
				'id'          => '_subscription_trial_length',
246
				'class'       => 'wc_input_subscription_trial_length',
247
				'label'       => __( 'Free Trial', WCSATT_STT::TEXT_DOMAIN ),
248
				'name'        => 'wcsatt_schemes[' . $index . '][subscription_trial_length]',
249
				'value'       => $subscription_trial_length
250
			) );
251
252
			// Trial Period
253
			woocommerce_wp_select( array(
254
				'id'          => '_subscription_trial_period',
255
				'class'       => 'wc_input_subscription_trial_period',
256
				'label'       => __( 'Subscription Trial Period', WCSATT_STT::TEXT_DOMAIN ),
257
				'options'     => wcs_get_available_time_periods(),
258
				// translators: placeholder is trial period validation message if passed an invalid value (e.g. "Trial period can not exceed 4 weeks")
259
				'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() ),
260
				'desc_tip'    => true,
261
				'value'       => WC_Subscriptions_Product::get_trial_period( $post_id ), // Explicitly set value in to ensure backward compatibility
262
				'name'        => 'wcsatt_schemes[' . $index . '][subscription_trial_period]',
263
				'value'       => $subscription_trial_period
264
		) );
265
		} // END wcsatt_stt_fields()
266
267
		/**
268
		 * Filters the subscription scheme data to pass the 
269
		 * sign up and trial options when saving.
270
		 *
271
		 * @param  ini $posted_scheme
272
		 * @param  string $product_type
273
		 * @return void
274
		 */
275
		public function wcsatt_stt_process_scheme_data( $posted_scheme, $product_type ) {
276
			// Copy variable type fields.
277
			if ( 'variable' == $product_type ) {
278
				if ( isset( $posted_scheme[ 'subscription_sign_up_fee_variable' ] ) ) {
279
					$posted_scheme[ 'subscription_sign_up_fee' ] = $posted_scheme[ 'subscription_sign_up_fee_variable' ];
280
				}
281
				if ( isset( $posted_scheme[ 'subscription_trial_length_variable' ] ) ) {
282
					$posted_scheme[ 'subscription_trial_length' ] = $posted_scheme[ 'subscription_trial_length_variable' ];
283
				}
284
				if ( isset( $posted_scheme[ 'subscription_trial_period_variable' ] ) ) {
285
					$posted_scheme[ 'subscription_trial_period' ] = $posted_scheme[ 'subscription_trial_period_variable'];
286
				}
287
			}
288
289
			// Format subscription sign up fee.
290
			if ( isset( $posted_scheme[ 'subscription_sign_up_fee' ] ) ) {
291
				$posted_scheme[ 'subscription_sign_up_fee' ] = ( $posted_scheme[ 'subscription_sign_up_fee' ] === '' ) ? '' : wc_format_decimal( $posted_scheme[ 'subscription_sign_up_fee' ] );
292
			}
293
294
			// Make sure trial period is within allowable range.
295
			$subscription_ranges = wcs_get_subscription_ranges();
296
			$max_trial_length = count( $subscription_ranges[ $posted_scheme[ 'subscription_trial_period' ] ] ) - 1;
297
298
			// Format subscription trial length.
299
			if ( isset( $posted_scheme[ 'subscription_trial_length' ] ) && $posted_scheme[ 'subscription_trial_length' ] > $max_trial_length ) {
300
				$posted_scheme[ 'subscription_trial_length' ] = ( $posted_scheme[ 'subscription_trial_length' ] === '' ) ? '' : absint( $posted_scheme[ 'subscription_trial_length' ] );
301
			}
302
303
			// Format subscription trial period.
304
			$trial_periods = apply_filters( 'wcsatt_stt_trial_periods', array( 'day', 'week', 'month', 'year' ) );
305
			if ( isset( $posted_scheme[ 'subscription_trial_period' ] ) && in_array( $posted_scheme[ 'subscription_trial_period' ], $trial_periods ) ) {
306
				$posted_scheme[ 'subscription_trial_period' ] = trim( $posted_scheme[ 'subscription_trial_period' ] );
307
			}
308
309
			return $posted_scheme;
310
		} // END wcsatt_stt_process_scheme_data()
311
312
		/**
313
		 * Adds the additional subscription scheme data for products with attached subscription schemes.
314
		 *
315
		 * @param  object     $_product
316
		 * @param  array      $subscription_scheme
317
		 * @param  WC_Product $product
318
		 * @return string
319
		 */
320
		public function add_sub_scheme_data_price_html( $_product, $subscription_scheme, $product ) {
0 ignored issues
show
Unused Code introduced by
The parameter $product is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
321
			if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) ) {
322
				$_product->subscription_sign_up_fee = $subscription_scheme[ 'subscription_sign_up_fee' ];
323
			}
324
325
			if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) ) {
326
				$_product->subscription_trial_length = $subscription_scheme[ 'subscription_trial_length' ];
327
			}
328
329
			if ( isset( $subscription_scheme[ 'subscription_trial_period' ] ) ) {
330
				$_product->subscription_trial_period = $subscription_scheme[ 'subscription_trial_period' ];
331
			}
332
333
			return $_product;
334
		} // END add_sub_scheme_data_price_html()
335
336
		/**
337
		 * Adds the extra subscription scheme data to the product object.
338
		 * This allows the subscription price to change the initial and
339
		 * recurring subscriptions.
340
		 *
341
		 * @param  object $_cloned
342
		 * @param  array  $subscription_scheme
343
		 * @return object
344
		 */
345
		public function sub_product_scheme_option( $_cloned, $subscription_scheme ) {
346
			if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) && $subscription_scheme[ 'subscription_sign_up_fee' ] > 0 ) {
347
				$_cloned->subscription_sign_up_fee = $subscription_scheme[ 'subscription_sign_up_fee' ];
348
			}
349
350
			if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) && 0 != $subscription_scheme[ 'subscription_trial_length' ] ) {
351
				$_cloned->subscription_trial_length = $subscription_scheme[ 'subscription_trial_length' ];
352
				$_cloned->subscription_trial_period = $subscription_scheme[ 'subscription_trial_period' ];
353
			}
354
355
			return $_cloned;
356
		} // END sub_product_scheme_option()
357
358
		/**
359
		 * Filters the price string to include the sign up fee and/or trial 
360
		 * to pass per subscription scheme option.
361
		 *
362
		 * @param  array $prices
363
		 * @param  array $subscription_scheme
364
		 * @return array
365
		 */
366
		public function get_price_string( $prices, $subscription_scheme ) {
367
			if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) && $subscription_scheme[ 'subscription_sign_up_fee' ] > 0 ) {
368
				$prices[ 'sign_up_fee' ] = true;
369
			}
370
371
			if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) && 0 != $subscription_scheme[ 'subscription_trial_length' ] ) {
372
				$prices[ 'trial_length' ] = true;
373
			}
374
375
			return $prices;
376
		} // END get_price_string()
377
378
		/**
379
		 * Filter the suffix price string.
380
		 *
381
		 * @param object     $_product
382
		 * @param array      $subscription_scheme
383
		 * @param WC_Product $product
384
		 * @return string
385
		 */
386
		/*public function filter_suffix_price_html( $_product, $subscription_scheme, $product ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
387
			$subscription_string = '';
388
389
			if ( isset( $_product->subscription_trial_length ) && 0 != $_product->subscription_trial_length ) {
390
				$trial_string = wcs_get_subscription_trial_period_strings( $_product->subscription_trial_length, $_product->subscription_trial_period );
391
				// translators: 1$: subscription string (e.g. "$15 on March 15th every 3 years for 6 years"), 2$: trial length (e.g.: "with 4 months free trial")
392
				$subscription_string = sprintf( __( '%1$s with %2$s free trial', WCSATT_STT::TEXT_DOMAIN ), $subscription_string, $trial_string );
393
			}
394
395
			$sign_up_fee = $_product->subscription_sign_up_fee;
396
397
			if ( is_numeric( $sign_up_fee ) ) {
398
				$sign_up_fee = wc_price( $sign_up_fee );
399
			}
400
401
			if ( isset( $_product->subscription_sign_up_fee ) && $_product->subscription_sign_up_fee > 0 ) {
402
				// translators: 1$: subscription string (e.g. "$15 on March 15th every 3 years for 6 years with 2 months free trial"), 2$: signup fee price (e.g. "and a $30 sign-up fee")
403
				$subscription_string = sprintf( __( '%1$s and a %2$s sign-up fee', WCSATT_STT::TEXT_DOMAIN ), $subscription_string, $sign_up_fee );
404
			}
405
406
			return $subscription_string;
407
		}*/
408
409
		/**
410
		 * Adds the sign-up and/or trial data to the subscription scheme prices.
411
		 *
412
		 * @param  array $prices
413
		 * @param  array $subscription_scheme
414
		 * @return array
415
		 */
416
		public function add_subscription_scheme_prices( $prices, $subscription_scheme ) {
417
			if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) ) {
418
				$prices[ 'sign_up_fee' ] = $subscription_scheme[ 'subscription_sign_up_fee' ];
419
			}
420
421
			if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) ) {
422
				$prices[ 'trial_length' ] = $subscription_scheme[ 'subscription_trial_length' ];
423
			}
424
425
			if ( isset( $subscription_scheme[ 'subscription_trial_period' ] ) ) {
426
				$prices[ 'trial_period' ] = $subscription_scheme[ 'subscription_trial_period' ];
427
			}
428
429
			return $prices;
430
		} // END add_subscription_scheme_prices()
431
432
		/**
433
		 * Updates the cart item data for a subscription product that
434
		 * has a sign-up fee and/or trial period applied.
435
		 *
436
		 * @param  array $cart_item
437
		 * @return array
438
		 */
439
		public function update_cart_item_sub_data( $cart_item ) {
440
			$active_scheme = WCS_ATT_Schemes::get_active_subscription_scheme( $cart_item );
441
442
			$subscription_prices = WCS_ATT_Scheme_Prices::get_active_subscription_scheme_prices( $cart_item, $active_scheme );
443
444
			if ( $active_scheme && $cart_item['data']->is_converted_to_sub == 'yes' ) {
445
446
				// Subscription Price
447
				$price = $cart_item['data']->subscription_price;
448
449
				// Is there a sign up fee?
450
				$sign_up_fee = isset( $subscription_prices['sign_up_fee'] ) ? $subscription_prices['sign_up_fee'] : '';
451
452
				// Put them both together.
453
				$new_price = $price + $sign_up_fee;
454
455
				if ( $sign_up_fee > 0 ) {
456
					$cart_item['data']->initial_amount = $new_price;
457
					$cart_item['data']->subscription_sign_up_fee = $sign_up_fee;
458
				}
459
460
				$trial_length = isset( $subscription_prices['trial_length'] ) ? $subscription_prices['trial_length'] : 0;
461
				$trial_period = isset( $subscription_prices['trial_period'] ) ? $subscription_prices['trial_period'] : '';
462
463
				// If a trial length is more than zero then re-adjust the price.
464
				if ( $trial_length > 0 ) {
465
466
					/*$cart_item['data']->price = $new_price;
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
467
					$cart_item['data']->subscription_price = $new_price;
468
					$cart_item['data']->sale_price = $new_price;
469
					$cart_item['data']->regular_price = $new_price;*/
470
471
					$cart_item['data']->subscription_trial_length = $trial_length;
472
					$cart_item['data']->subscription_trial_period = $trial_period;
473
				} else {
474
					$cart_item['data']->subscription_trial_length = 0;
475
					$cart_item['data']->subscription_trial_period = '';
476
				}
477
478
			}
479
480
			return $cart_item;
481
		} // END update_cart_item_sub_data()
482
483
	} // END class
484
485
} // END if class exists
486
487
return WCSATT_STT::instance();