|
@@ -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,31 +134,31 @@ 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 on the 'wcsatt_sub_product_scheme_option' filter. |
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 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 ); |
|
146
|
+ add_filter('wcsatt_get_single_product_price_string', array($this, 'get_price_string'), 10, 2); |
147
|
147
|
|
148
|
148
|
// Filters the lowest price string to include the sign up fee on the 'wcsatt_get_single_product_lowest_price_string' filter. |
149
|
|
- add_filter( 'wcsatt_get_single_product_lowest_price_string', array( $this, 'get_lowest_price_string' ), 10, 2 ); |
|
149
|
+ add_filter('wcsatt_get_single_product_lowest_price_string', array($this, 'get_lowest_price_string'), 10, 2); |
150
|
150
|
|
151
|
151
|
// Filters the suffix price html on the 'wcsatt_suffix_price_html' filter. |
152
|
152
|
//add_filter( 'wcsatt_suffix_price_html', array( $this, 'filter_suffix_price_html' ), 10, 1 ); |
153
|
153
|
|
154
|
154
|
// Filters the lowest price subscription scheme data on the 'wcsatt_get_lowest_price_sub_scheme_data' filter. |
155
|
|
- add_filter( 'wcsatt_get_lowest_price_sub_scheme_data', array( $this, 'get_lowest_price_sub_scheme_data' ), 10, 2 ); |
|
155
|
+ add_filter('wcsatt_get_lowest_price_sub_scheme_data', array($this, 'get_lowest_price_sub_scheme_data'), 10, 2); |
156
|
156
|
|
157
|
157
|
// Adds the sign-up and/or trial data to the subscription scheme prices on the 'wcsatt_subscription_scheme_prices' filter. |
158
|
|
- add_filter( 'wcsatt_subscription_scheme_prices', array( $this, 'add_subscription_scheme_prices' ), 10, 2 ); |
|
158
|
+ add_filter('wcsatt_subscription_scheme_prices', array($this, 'add_subscription_scheme_prices'), 10, 2); |
159
|
159
|
|
160
|
160
|
// Overrides the price of the subscription for sign up fee and/or trial on the 'wcsatt_cart_item' filter. |
161
|
|
- add_filter( 'wcsatt_cart_item', array( $this, 'update_cart_item_sub_data' ), 10, 1 ); |
|
161
|
+ add_filter('wcsatt_cart_item', array($this, 'update_cart_item_sub_data'), 10, 1); |
162
|
162
|
} // END init_plugin() |
163
|
163
|
|
164
|
164
|
/** |
|
@@ -171,10 +171,10 @@ discard block |
|
|
block discarded – undo |
171
|
171
|
//add_action( 'wcsatt_subscription_scheme_content', array( $this, 'wcsatt_stt_fields' ), 15, 3 ); |
172
|
172
|
|
173
|
173
|
// Subscription scheme options displayed on the 'wcsatt_subscription_scheme_product_content' action. |
174
|
|
- add_action( 'wcsatt_subscription_scheme_product_content', array( $this, 'wcsatt_stt_fields' ), 15, 3 ); |
|
174
|
+ add_action('wcsatt_subscription_scheme_product_content', array($this, 'wcsatt_stt_fields'), 15, 3); |
175
|
175
|
|
176
|
176
|
// Filter the subscription scheme data to process the sign up and trial options on the ''wcsatt_subscription_scheme_process_scheme_data' filter. |
177
|
|
- add_filter( 'wcsatt_subscription_scheme_process_scheme_data', array( $this, 'wcsatt_stt_process_scheme_data' ), 10, 2 ); |
|
177
|
+ add_filter('wcsatt_subscription_scheme_process_scheme_data', array($this, 'wcsatt_stt_process_scheme_data'), 10, 2); |
178
|
178
|
} // END admin_wcsatt_stt_product_meta() |
179
|
179
|
|
180
|
180
|
/** |
|
@@ -184,10 +184,10 @@ discard block |
|
|
block discarded – undo |
184
|
184
|
* @param mixed $file Plugin Base file |
185
|
185
|
* @return array |
186
|
186
|
*/ |
187
|
|
- public function plugin_meta_links( $links, $file, $data, $status ) { |
188
|
|
- if ( $file == plugin_basename( __FILE__ ) ) { |
189
|
|
- $author1 = '<a href="' . $data[ 'AuthorURI' ] . '">' . $data[ 'Author' ] . '</a>'; |
190
|
|
- $links[ 1 ] = sprintf( __( 'By %s', WCSATT_STT::TEXT_DOMAIN ), $author1 ); |
|
187
|
+ public function plugin_meta_links($links, $file, $data, $status) { |
|
188
|
+ if ($file == plugin_basename(__FILE__)) { |
|
189
|
+ $author1 = '<a href="'.$data['AuthorURI'].'">'.$data['Author'].'</a>'; |
|
190
|
+ $links[1] = sprintf(__('By %s', WCSATT_STT::TEXT_DOMAIN), $author1); |
191
|
191
|
} |
192
|
192
|
|
193
|
193
|
return $links; |
|
@@ -199,14 +199,14 @@ discard block |
|
|
block discarded – undo |
199
|
199
|
* @param array $defaults |
200
|
200
|
* @return void |
201
|
201
|
*/ |
202
|
|
- public static function add_default_subscription_schemes_content( $defaults ) { |
|
202
|
+ public static function add_default_subscription_schemes_content($defaults) { |
203
|
203
|
$new_defaults = array( |
204
|
204
|
'subscription_sign_up_fee' => '', |
205
|
205
|
'subscription_trial_length' => '', |
206
|
206
|
'subscription_trial_period' => '' |
207
|
207
|
); |
208
|
208
|
|
209
|
|
- return array_merge( $new_defaults, $defaults ); |
|
209
|
+ return array_merge($new_defaults, $defaults); |
210
|
210
|
} // END add_default_subscription_schemes_content() |
211
|
211
|
|
212
|
212
|
/** |
|
@@ -217,11 +217,11 @@ discard block |
|
|
block discarded – undo |
217
|
217
|
* @param int $post_id |
218
|
218
|
* @return void |
219
|
219
|
*/ |
220
|
|
- public function wcsatt_stt_fields( $index, $scheme_data, $post_id ) { |
221
|
|
- if ( ! empty( $scheme_data ) ) { |
222
|
|
- $subscription_sign_up_fee = ! empty( $scheme_data[ 'subscription_sign_up_fee' ] ) ? $scheme_data[ 'subscription_sign_up_fee' ] : ''; |
223
|
|
- $subscription_trial_length = isset( $scheme_data[ 'subscription_trial_length' ] ) ? $scheme_data[ 'subscription_trial_length' ] : 0; |
224
|
|
- $subscription_trial_period = isset( $scheme_data[ 'subscription_trial_period' ] ) ? $scheme_data[ 'subscription_trial_period' ] : ''; |
|
220
|
+ public function wcsatt_stt_fields($index, $scheme_data, $post_id) { |
|
221
|
+ if (!empty($scheme_data)) { |
|
222
|
+ $subscription_sign_up_fee = !empty($scheme_data['subscription_sign_up_fee']) ? $scheme_data['subscription_sign_up_fee'] : ''; |
|
223
|
+ $subscription_trial_length = isset($scheme_data['subscription_trial_length']) ? $scheme_data['subscription_trial_length'] : 0; |
|
224
|
+ $subscription_trial_period = isset($scheme_data['subscription_trial_period']) ? $scheme_data['subscription_trial_period'] : ''; |
225
|
225
|
} else { |
226
|
226
|
$subscription_sign_up_fee = ''; |
227
|
227
|
$subscription_trial_length = 0; |
|
@@ -229,45 +229,45 @@ discard block |
|
|
block discarded – undo |
229
|
229
|
} |
230
|
230
|
|
231
|
231
|
// Sign-up Fee |
232
|
|
- woocommerce_wp_text_input( array( |
|
232
|
+ woocommerce_wp_text_input(array( |
233
|
233
|
'id' => '_subscription_sign_up_fee', |
234
|
234
|
'class' => 'wc_input_subscription_intial_price', |
235
|
235
|
// translators: %s is a currency symbol / code |
236
|
|
- 'label' => sprintf( __( 'Sign-up Fee (%s)', WCSATT_STT::TEXT_DOMAIN ), get_woocommerce_currency_symbol() ), |
237
|
|
- 'placeholder' => _x( 'e.g. 9.90', 'example price', WCSATT_STT::TEXT_DOMAIN ), |
238
|
|
- '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 ), |
|
236
|
+ 'label' => sprintf(__('Sign-up Fee (%s)', WCSATT_STT::TEXT_DOMAIN), get_woocommerce_currency_symbol()), |
|
237
|
+ 'placeholder' => _x('e.g. 9.90', 'example price', WCSATT_STT::TEXT_DOMAIN), |
|
238
|
+ '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), |
239
|
239
|
'desc_tip' => true, |
240
|
240
|
'type' => 'text', |
241
|
241
|
'custom_attributes' => array( |
242
|
242
|
'step' => 'any', |
243
|
243
|
'min' => '0', |
244
|
244
|
), |
245
|
|
- 'name' => 'wcsatt_schemes[' . $index . '][subscription_sign_up_fee]', |
|
245
|
+ 'name' => 'wcsatt_schemes['.$index.'][subscription_sign_up_fee]', |
246
|
246
|
'value' => $subscription_sign_up_fee |
247
|
|
- ) ); |
|
247
|
+ )); |
248
|
248
|
|
249
|
249
|
// Trial Length |
250
|
|
- woocommerce_wp_text_input( array( |
|
250
|
+ woocommerce_wp_text_input(array( |
251
|
251
|
'id' => '_subscription_trial_length', |
252
|
252
|
'class' => 'wc_input_subscription_trial_length', |
253
|
|
- 'label' => __( 'Free Trial', WCSATT_STT::TEXT_DOMAIN ), |
254
|
|
- 'name' => 'wcsatt_schemes[' . $index . '][subscription_trial_length]', |
|
253
|
+ 'label' => __('Free Trial', WCSATT_STT::TEXT_DOMAIN), |
|
254
|
+ 'name' => 'wcsatt_schemes['.$index.'][subscription_trial_length]', |
255
|
255
|
'value' => $subscription_trial_length |
256
|
|
- ) ); |
|
256
|
+ )); |
257
|
257
|
|
258
|
258
|
// Trial Period |
259
|
|
- woocommerce_wp_select( array( |
|
259
|
+ woocommerce_wp_select(array( |
260
|
260
|
'id' => '_subscription_trial_period', |
261
|
261
|
'class' => 'wc_input_subscription_trial_period', |
262
|
|
- 'label' => __( 'Subscription Trial Period', WCSATT_STT::TEXT_DOMAIN ), |
|
262
|
+ 'label' => __('Subscription Trial Period', WCSATT_STT::TEXT_DOMAIN), |
263
|
263
|
'options' => wcs_get_available_time_periods(), |
264
|
264
|
// translators: placeholder is trial period validation message if passed an invalid value (e.g. "Trial period can not exceed 4 weeks") |
265
|
|
- '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() ), |
|
265
|
+ '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()), |
266
|
266
|
'desc_tip' => true, |
267
|
|
- 'value' => WC_Subscriptions_Product::get_trial_period( $post_id ), // Explicitly set value in to ensure backward compatibility |
268
|
|
- 'name' => 'wcsatt_schemes[' . $index . '][subscription_trial_period]', |
|
267
|
+ 'value' => WC_Subscriptions_Product::get_trial_period($post_id), // Explicitly set value in to ensure backward compatibility |
|
268
|
+ 'name' => 'wcsatt_schemes['.$index.'][subscription_trial_period]', |
269
|
269
|
'value' => $subscription_trial_period |
270
|
|
- ) ); |
|
270
|
+ )); |
271
|
271
|
} // END wcsatt_stt_fields() |
272
|
272
|
|
273
|
273
|
/** |
|
@@ -278,38 +278,38 @@ discard block |
|
|
block discarded – undo |
278
|
278
|
* @param string $product_type |
279
|
279
|
* @return void |
280
|
280
|
*/ |
281
|
|
- public function wcsatt_stt_process_scheme_data( $posted_scheme, $product_type ) { |
|
281
|
+ public function wcsatt_stt_process_scheme_data($posted_scheme, $product_type) { |
282
|
282
|
// Copy variable type fields. |
283
|
|
- if ( 'variable' == $product_type ) { |
284
|
|
- if ( isset( $posted_scheme[ 'subscription_sign_up_fee_variable' ] ) ) { |
285
|
|
- $posted_scheme[ 'subscription_sign_up_fee' ] = $posted_scheme[ 'subscription_sign_up_fee_variable' ]; |
|
283
|
+ if ('variable' == $product_type) { |
|
284
|
+ if (isset($posted_scheme['subscription_sign_up_fee_variable'])) { |
|
285
|
+ $posted_scheme['subscription_sign_up_fee'] = $posted_scheme['subscription_sign_up_fee_variable']; |
286
|
286
|
} |
287
|
|
- if ( isset( $posted_scheme[ 'subscription_trial_length_variable' ] ) ) { |
288
|
|
- $posted_scheme[ 'subscription_trial_length' ] = $posted_scheme[ 'subscription_trial_length_variable' ]; |
|
287
|
+ if (isset($posted_scheme['subscription_trial_length_variable'])) { |
|
288
|
+ $posted_scheme['subscription_trial_length'] = $posted_scheme['subscription_trial_length_variable']; |
289
|
289
|
} |
290
|
|
- if ( isset( $posted_scheme[ 'subscription_trial_period_variable' ] ) ) { |
291
|
|
- $posted_scheme[ 'subscription_trial_period' ] = $posted_scheme[ 'subscription_trial_period_variable']; |
|
290
|
+ if (isset($posted_scheme['subscription_trial_period_variable'])) { |
|
291
|
+ $posted_scheme['subscription_trial_period'] = $posted_scheme['subscription_trial_period_variable']; |
292
|
292
|
} |
293
|
293
|
} |
294
|
294
|
|
295
|
295
|
// Format subscription sign up fee. |
296
|
|
- if ( isset( $posted_scheme[ 'subscription_sign_up_fee' ] ) ) { |
297
|
|
- $posted_scheme[ 'subscription_sign_up_fee' ] = ( $posted_scheme[ 'subscription_sign_up_fee' ] === '' ) ? '' : wc_format_decimal( $posted_scheme[ 'subscription_sign_up_fee' ] ); |
|
296
|
+ if (isset($posted_scheme['subscription_sign_up_fee'])) { |
|
297
|
+ $posted_scheme['subscription_sign_up_fee'] = ($posted_scheme['subscription_sign_up_fee'] === '') ? '' : wc_format_decimal($posted_scheme['subscription_sign_up_fee']); |
298
|
298
|
} |
299
|
299
|
|
300
|
300
|
// Make sure trial period is within allowable range. |
301
|
301
|
$subscription_ranges = wcs_get_subscription_ranges(); |
302
|
|
- $max_trial_length = count( $subscription_ranges[ $posted_scheme[ 'subscription_trial_period' ] ] ) - 1; |
|
302
|
+ $max_trial_length = count($subscription_ranges[$posted_scheme['subscription_trial_period']]) - 1; |
303
|
303
|
|
304
|
304
|
// Format subscription trial length. |
305
|
|
- if ( isset( $posted_scheme[ 'subscription_trial_length' ] ) && $posted_scheme[ 'subscription_trial_length' ] > $max_trial_length ) { |
306
|
|
- $posted_scheme[ 'subscription_trial_length' ] = ( $posted_scheme[ 'subscription_trial_length' ] === '' ) ? '' : absint( $posted_scheme[ 'subscription_trial_length' ] ); |
|
305
|
+ if (isset($posted_scheme['subscription_trial_length']) && $posted_scheme['subscription_trial_length'] > $max_trial_length) { |
|
306
|
+ $posted_scheme['subscription_trial_length'] = ($posted_scheme['subscription_trial_length'] === '') ? '' : absint($posted_scheme['subscription_trial_length']); |
307
|
307
|
} |
308
|
308
|
|
309
|
309
|
// Format subscription trial period. |
310
|
|
- $trial_periods = apply_filters( 'wcsatt_stt_trial_periods', array( 'day', 'week', 'month', 'year' ) ); |
311
|
|
- if ( isset( $posted_scheme[ 'subscription_trial_period' ] ) && in_array( $posted_scheme[ 'subscription_trial_period' ], $trial_periods ) ) { |
312
|
|
- $posted_scheme[ 'subscription_trial_period' ] = trim( $posted_scheme[ 'subscription_trial_period' ] ); |
|
310
|
+ $trial_periods = apply_filters('wcsatt_stt_trial_periods', array('day', 'week', 'month', 'year')); |
|
311
|
+ if (isset($posted_scheme['subscription_trial_period']) && in_array($posted_scheme['subscription_trial_period'], $trial_periods)) { |
|
312
|
+ $posted_scheme['subscription_trial_period'] = trim($posted_scheme['subscription_trial_period']); |
313
|
313
|
} |
314
|
314
|
|
315
|
315
|
return $posted_scheme; |
|
@@ -323,17 +323,17 @@ discard block |
|
|
block discarded – undo |
323
|
323
|
* @param WC_Product $product |
324
|
324
|
* @return string |
325
|
325
|
*/ |
326
|
|
- public function add_sub_scheme_data_price_html( $_product, $subscription_scheme, $product ) { |
327
|
|
- if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) ) { |
328
|
|
- $_product->subscription_sign_up_fee = $subscription_scheme[ 'subscription_sign_up_fee' ]; |
|
326
|
+ public function add_sub_scheme_data_price_html($_product, $subscription_scheme, $product) { |
|
327
|
+ if (isset($subscription_scheme['subscription_sign_up_fee'])) { |
|
328
|
+ $_product->subscription_sign_up_fee = $subscription_scheme['subscription_sign_up_fee']; |
329
|
329
|
} |
330
|
330
|
|
331
|
|
- if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) ) { |
332
|
|
- $_product->subscription_trial_length = $subscription_scheme[ 'subscription_trial_length' ]; |
|
331
|
+ if (isset($subscription_scheme['subscription_trial_length'])) { |
|
332
|
+ $_product->subscription_trial_length = $subscription_scheme['subscription_trial_length']; |
333
|
333
|
} |
334
|
334
|
|
335
|
|
- if ( isset( $subscription_scheme[ 'subscription_trial_period' ] ) ) { |
336
|
|
- $_product->subscription_trial_period = $subscription_scheme[ 'subscription_trial_period' ]; |
|
335
|
+ if (isset($subscription_scheme['subscription_trial_period'])) { |
|
336
|
+ $_product->subscription_trial_period = $subscription_scheme['subscription_trial_period']; |
337
|
337
|
} |
338
|
338
|
|
339
|
339
|
return $_product; |
|
@@ -348,14 +348,14 @@ discard block |
|
|
block discarded – undo |
348
|
348
|
* @param array $subscription_scheme |
349
|
349
|
* @return object |
350
|
350
|
*/ |
351
|
|
- public function sub_product_scheme_option( $_cloned, $subscription_scheme ) { |
352
|
|
- if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) && $subscription_scheme[ 'subscription_sign_up_fee' ] > 0 ) { |
353
|
|
- $_cloned->subscription_sign_up_fee = $subscription_scheme[ 'subscription_sign_up_fee' ]; |
|
351
|
+ public function sub_product_scheme_option($_cloned, $subscription_scheme) { |
|
352
|
+ if (isset($subscription_scheme['subscription_sign_up_fee']) && $subscription_scheme['subscription_sign_up_fee'] > 0) { |
|
353
|
+ $_cloned->subscription_sign_up_fee = $subscription_scheme['subscription_sign_up_fee']; |
354
|
354
|
} |
355
|
355
|
|
356
|
|
- if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) && 0 != $subscription_scheme[ 'subscription_trial_length' ] ) { |
357
|
|
- $_cloned->subscription_trial_length = $subscription_scheme[ 'subscription_trial_length' ]; |
358
|
|
- $_cloned->subscription_trial_period = $subscription_scheme[ 'subscription_trial_period' ]; |
|
356
|
+ if (isset($subscription_scheme['subscription_trial_length']) && 0 != $subscription_scheme['subscription_trial_length']) { |
|
357
|
+ $_cloned->subscription_trial_length = $subscription_scheme['subscription_trial_length']; |
|
358
|
+ $_cloned->subscription_trial_period = $subscription_scheme['subscription_trial_period']; |
359
|
359
|
} |
360
|
360
|
|
361
|
361
|
return $_cloned; |
|
@@ -369,13 +369,13 @@ discard block |
|
|
block discarded – undo |
369
|
369
|
* @param array $subscription_scheme |
370
|
370
|
* @return array |
371
|
371
|
*/ |
372
|
|
- public function get_price_string( $prices, $subscription_scheme ) { |
373
|
|
- if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) && $subscription_scheme[ 'subscription_sign_up_fee' ] > 0 ) { |
374
|
|
- $prices[ 'sign_up_fee' ] = $subscription_scheme[ 'subscription_sign_up_fee' ]; |
|
372
|
+ public function get_price_string($prices, $subscription_scheme) { |
|
373
|
+ if (isset($subscription_scheme['subscription_sign_up_fee']) && $subscription_scheme['subscription_sign_up_fee'] > 0) { |
|
374
|
+ $prices['sign_up_fee'] = $subscription_scheme['subscription_sign_up_fee']; |
375
|
375
|
} |
376
|
376
|
|
377
|
|
- if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) && 0 != $subscription_scheme[ 'subscription_trial_length' ] ) { |
378
|
|
- $prices[ 'trial_length' ] = true; |
|
377
|
+ if (isset($subscription_scheme['subscription_trial_length']) && 0 != $subscription_scheme['subscription_trial_length']) { |
|
378
|
+ $prices['trial_length'] = true; |
379
|
379
|
} |
380
|
380
|
|
381
|
381
|
return $prices; |
|
@@ -389,9 +389,9 @@ discard block |
|
|
block discarded – undo |
389
|
389
|
* @param array $lowest_subscription_scheme |
390
|
390
|
* @return array |
391
|
391
|
*/ |
392
|
|
- public function get_lowest_price_string( $prices, $lowest_subscription_scheme ) { |
393
|
|
- if ( isset( $lowest_subscription_scheme[ 'sign_up_fee' ] ) && $lowest_subscription_scheme[ 'sign_up_fee' ] > 0 ) { |
394
|
|
- $prices[ 'sign_up_fee' ] = $lowest_subscription_scheme[ 'sign_up_fee' ]; |
|
392
|
+ public function get_lowest_price_string($prices, $lowest_subscription_scheme) { |
|
393
|
+ if (isset($lowest_subscription_scheme['sign_up_fee']) && $lowest_subscription_scheme['sign_up_fee'] > 0) { |
|
394
|
+ $prices['sign_up_fee'] = $lowest_subscription_scheme['sign_up_fee']; |
395
|
395
|
} |
396
|
396
|
|
397
|
397
|
return $prices; |
|
@@ -435,8 +435,8 @@ discard block |
|
|
block discarded – undo |
435
|
435
|
* @param array $lowest_scheme |
436
|
436
|
* @return array |
437
|
437
|
*/ |
438
|
|
- public function get_lowest_price_sub_scheme_data( $data, $lowest_scheme ) { |
439
|
|
- if ( isset( $lowest_scheme['subscription_sign_up_fee'] ) && $lowest_scheme['subscription_sign_up_fee'] > 0 ) { |
|
438
|
+ public function get_lowest_price_sub_scheme_data($data, $lowest_scheme) { |
|
439
|
+ if (isset($lowest_scheme['subscription_sign_up_fee']) && $lowest_scheme['subscription_sign_up_fee'] > 0) { |
440
|
440
|
$data['sign_up_fee'] = $lowest_scheme['subscription_sign_up_fee']; |
441
|
441
|
} |
442
|
442
|
|
|
@@ -450,17 +450,17 @@ discard block |
|
|
block discarded – undo |
450
|
450
|
* @param array $subscription_scheme |
451
|
451
|
* @return array |
452
|
452
|
*/ |
453
|
|
- public function add_subscription_scheme_prices( $prices, $subscription_scheme ) { |
454
|
|
- if ( isset( $subscription_scheme[ 'subscription_sign_up_fee' ] ) ) { |
455
|
|
- $prices[ 'sign_up_fee' ] = $subscription_scheme[ 'subscription_sign_up_fee' ]; |
|
453
|
+ public function add_subscription_scheme_prices($prices, $subscription_scheme) { |
|
454
|
+ if (isset($subscription_scheme['subscription_sign_up_fee'])) { |
|
455
|
+ $prices['sign_up_fee'] = $subscription_scheme['subscription_sign_up_fee']; |
456
|
456
|
} |
457
|
457
|
|
458
|
|
- if ( isset( $subscription_scheme[ 'subscription_trial_length' ] ) ) { |
459
|
|
- $prices[ 'trial_length' ] = $subscription_scheme[ 'subscription_trial_length' ]; |
|
458
|
+ if (isset($subscription_scheme['subscription_trial_length'])) { |
|
459
|
+ $prices['trial_length'] = $subscription_scheme['subscription_trial_length']; |
460
|
460
|
} |
461
|
461
|
|
462
|
|
- if ( isset( $subscription_scheme[ 'subscription_trial_period' ] ) ) { |
463
|
|
- $prices[ 'trial_period' ] = $subscription_scheme[ 'subscription_trial_period' ]; |
|
462
|
+ if (isset($subscription_scheme['subscription_trial_period'])) { |
|
463
|
+ $prices['trial_period'] = $subscription_scheme['subscription_trial_period']; |
464
|
464
|
} |
465
|
465
|
|
466
|
466
|
return $prices; |
|
@@ -473,32 +473,32 @@ discard block |
|
|
block discarded – undo |
473
|
473
|
* @param array $cart_item |
474
|
474
|
* @return array |
475
|
475
|
*/ |
476
|
|
- public function update_cart_item_sub_data( $cart_item ) { |
477
|
|
- $active_scheme = WCS_ATT_Schemes::get_active_subscription_scheme( $cart_item ); |
|
476
|
+ public function update_cart_item_sub_data($cart_item) { |
|
477
|
+ $active_scheme = WCS_ATT_Schemes::get_active_subscription_scheme($cart_item); |
478
|
478
|
|
479
|
|
- $subscription_prices = WCS_ATT_Scheme_Prices::get_active_subscription_scheme_prices( $cart_item, $active_scheme ); |
|
479
|
+ $subscription_prices = WCS_ATT_Scheme_Prices::get_active_subscription_scheme_prices($cart_item, $active_scheme); |
480
|
480
|
|
481
|
|
- if ( $active_scheme && $cart_item['data']->is_converted_to_sub == 'yes' ) { |
|
481
|
+ if ($active_scheme && $cart_item['data']->is_converted_to_sub == 'yes') { |
482
|
482
|
|
483
|
483
|
// Subscription Price |
484
|
484
|
$price = $cart_item['data']->subscription_price; |
485
|
485
|
|
486
|
486
|
// Is there a sign up fee? |
487
|
|
- $sign_up_fee = isset( $subscription_prices['sign_up_fee'] ) ? $subscription_prices['sign_up_fee'] : ''; |
|
487
|
+ $sign_up_fee = isset($subscription_prices['sign_up_fee']) ? $subscription_prices['sign_up_fee'] : ''; |
488
|
488
|
|
489
|
489
|
// Put them both together. |
490
|
490
|
$new_price = $price + $sign_up_fee; |
491
|
491
|
|
492
|
|
- if ( $sign_up_fee > 0 ) { |
|
492
|
+ if ($sign_up_fee > 0) { |
493
|
493
|
$cart_item['data']->initial_amount = $new_price; |
494
|
494
|
$cart_item['data']->subscription_sign_up_fee = $sign_up_fee; |
495
|
495
|
} |
496
|
496
|
|
497
|
|
- $trial_length = isset( $subscription_prices['trial_length'] ) ? $subscription_prices['trial_length'] : 0; |
498
|
|
- $trial_period = isset( $subscription_prices['trial_period'] ) ? $subscription_prices['trial_period'] : ''; |
|
497
|
+ $trial_length = isset($subscription_prices['trial_length']) ? $subscription_prices['trial_length'] : 0; |
|
498
|
+ $trial_period = isset($subscription_prices['trial_period']) ? $subscription_prices['trial_period'] : ''; |
499
|
499
|
|
500
|
500
|
// If a trial length is more than zero then re-adjust the price. |
501
|
|
- if ( $trial_length > 0 ) { |
|
501
|
+ if ($trial_length > 0) { |
502
|
502
|
|
503
|
503
|
/*$cart_item['data']->price = $new_price; |
504
|
504
|
$cart_item['data']->subscription_price = $new_price; |