PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 2.3.0
Subscriptions for WooCommerce with Stripe Recurring Payments v2.3.0
2.4.0 2.3.0 2.2.0 2.1.0 2.0.0 1.11.2 1.11.1 1.11.0 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.6 1.9.5 trunk 1.3.0 1.3.1 1.3.2 1.4.0 All 65 releases
← All changes | includes/Admin/CancellationFlow.php +64 -10 2.2.0 → 2.3.0 View file →
@@ -301,19 +301,53 @@
301 301 'pro_locked' => $pro_locked,
302 302 ),
303 303 ),
304 304 array(
305 - 'type' => 'input',
305 + 'type' => 'join',
306 306 'field_data' => array(
307 - 'id' => 'subscrpt_cancellation_offer_percent',
308 307 'title' => __( 'Discount', 'subscription' ),
309 - 'type' => 'number',
310 - 'description' => __( 'Percentage off, applied store-wide by the generated coupon.', 'subscription' ),
311 - 'value' => self::offer_percent(),
312 - 'attrs' => array(
313 - 'min' => '1',
314 - 'max' => '100',
315 - 'step' => '1',
308 + 'description' => __( 'Percentage off, or a flat amount in the store currency, applied by the generated coupon.', 'subscription' ),
309 + 'elements' => array(
310 + SettingsHelper::inp_element(
311 + array(
312 + 'id' => 'subscrpt_cancellation_offer_percent',
313 + 'value' => self::offer_percent(),
314 + 'type' => 'number',
315 + 'style' => 'min-width:170px;width:170px;' . ( 'fixed' === self::offer_type() ? 'display:none;' : '' ),
316 + 'attributes' => array(
317 + 'min' => '1',
318 + 'max' => '100',
319 + 'step' => '1',
320 + ),
321 + ),
322 + true
323 + ),
324 + SettingsHelper::inp_element(
325 + array(
326 + 'id' => 'subscrpt_cancellation_offer_amount',
327 + 'value' => wc_format_decimal( self::offer_amount(), wc_get_price_decimals() ),
328 + 'type' => 'number',
329 + 'style' => 'min-width:170px;width:170px;' . ( 'fixed' === self::offer_type() ? '' : 'display:none;' ),
330 + 'attributes' => array(
331 + 'min' => '0',
332 + 'step' => (string) ( 1 / pow( 10, wc_get_price_decimals() ) ),
333 + ),
334 + ),
335 + true
336 + ),
337 + SettingsHelper::select_element(
338 + array(
339 + 'id' => 'subscrpt_cancellation_offer_type',
340 + 'class' => 'subscrpt-offer-type',
341 + 'options' => array(
342 + 'percent' => __( 'Percentage (%)', 'subscription' ),
343 + /* translators: %s: store currency symbol. */
344 + 'fixed' => sprintf( __( 'Flat (%s)', 'subscription' ), get_woocommerce_currency_symbol() ),
345 + ),
346 + 'selected' => self::offer_type(),
347 + ),
348 + true
349 + ),
316 350 ),
317 351 'pro_locked' => $pro_locked,
318 352 ),
319 353 ),
@@ -349,9 +383,29 @@
349 383 if ( ! subscrpt_pro_activated() ) {
350 384 return false;
351 385 }
352 386
353 - return '1' === get_option( 'subscrpt_cancellation_offer_enabled', '' ) && self::offer_percent() > 0;
387 + $value = 'fixed' === self::offer_type() ? self::offer_amount() : self::offer_percent();
388 +
389 + return '1' === get_option( 'subscrpt_cancellation_offer_enabled', '' ) && $value > 0;
390 + }
391 +
392 + /**
393 + * Configured discount type: `percent` or `fixed`.
394 + *
395 + * @return string
396 + */
397 + public static function offer_type() {
398 + return 'fixed' === get_option( 'subscrpt_cancellation_offer_type', 'percent' ) ? 'fixed' : 'percent';
399 + }
400 +
401 + /**
402 + * Configured flat discount amount, in the store currency.
403 + *
404 + * @return float
405 + */
406 + public static function offer_amount() {
407 + return max( 0, (float) get_option( 'subscrpt_cancellation_offer_amount', 0 ) );
354 408 }
355 409
356 410 /**
357 411 * Configured discount percentage.