PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 2.1.0
Subscriptions for WooCommerce with Stripe Recurring Payments v2.1.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/Illuminate/Helper.php +25 -7 1.11.1 → 2.1.0 View file →
@@ -1,5 +1,10 @@
1 1 <?php
2 +/**
3 + * Subscription helper utilities.
4 + *
5 + * @package SpringDevs\Subscription\Illuminate
6 + */
2 7
3 8 namespace SpringDevs\Subscription\Illuminate;
4 9
5 10 use SpringDevs\Subscription\Illuminate\Gateways\Stripe\Stripe;
@@ -59,15 +64,18 @@
59 64 * Get verbose status from status slug.
60 65 *
61 66 * @param string $status Status.
62 67 * @param bool $return_all Whether to return all statuses or a single status.
68 + *
69 + * @return string|array Verbose status label, or the full status map when $return_all is true.
63 70 */
64 - public static function get_verbose_status( $status, $return_all = false ): string|array {
71 + public static function get_verbose_status( $status, $return_all = false ) {
65 72 $statuses = array(
66 73 'pending' => __( 'Pending', 'subscription' ),
67 74 'active' => __( 'Active', 'subscription' ),
68 75 'on-hold' => __( 'On Hold', 'subscription' ),
69 76 'expired' => __( 'Expired', 'subscription' ),
77 + 'completed' => __( 'Completed', 'subscription' ),
70 78 'pe_cancelled' => __( 'Pending Cancellation', 'subscription' ),
71 79 'cancelled' => __( 'Cancelled', 'subscription' ),
72 80 'draft' => __( 'Draft', 'subscription' ),
73 81 'trash' => __( 'Trash', 'subscription' ),
@@ -512,9 +520,10 @@
512 520 'post_title' => "Subscription #{$subscription_id}",
513 521 )
514 522 );
515 523 // Check if this is a split payment subscription
516 - $payment_type = $product->get_meta( '_subscrpt_payment_type' ) ?: 'recurring';
524 + $payment_type = $product->get_meta( '_subscrpt_payment_type' );
525 + $payment_type = $payment_type ? $payment_type : 'recurring';
517 526 $max_payments = $product->get_meta( '_subscrpt_max_no_payment' );
518 527
519 528 $comment_content = '';
520 529 $activity_type = '';
@@ -977,10 +986,13 @@
977 986 foreach ( $cart_items as $key => $cart_item ) {
978 987 $product = $cart_item['data'];
979 988 if ( $product->is_type( 'simple' ) && isset( $cart_item['subscription'] ) ) {
980 989 $cart_subscription = $cart_item['subscription'];
981 - $type = ucfirst( $cart_subscription['type'] );
982 - $price_data = self::build_cart_recurring_price_data( $cart_item, $key, $type );
990 + // Cadence word must respect the frequency (plan items store the raw
991 + // plural interval, e.g. "months"): singular for 1, plural + count above.
992 + $sub_time = max( 1, (int) ( $cart_subscription['time'] ?? 1 ) );
993 + $type = ( 1 === $sub_time ? '' : $sub_time . ' ' ) . ucfirst( self::get_typos( $sub_time, $cart_subscription['type'] ) );
994 + $price_data = self::build_cart_recurring_price_data( $cart_item, $key, $type );
983 995
984 996 $recurrs[ $key ] = array_merge(
985 997 $price_data,
986 998 array(
@@ -987,9 +999,14 @@
987 999 'trial_status' => ! is_null( $cart_subscription['trial'] ),
988 1000 'start_date' => self::start_date( $cart_subscription['trial'] ),
989 1001 'next_date' => self::next_date( ( $cart_subscription['time'] ?? 1 ) . ' ' . $cart_subscription['type'], $cart_subscription['trial'] ),
990 1002 'can_user_cancel' => $cart_item['data']->get_meta( '_subscrpt_user_cancel' ),
991 - 'max_no_payment' => $cart_item['data']->get_meta( '_subscrpt_max_no_payment' ),
1003 + 'max_no_payment' => ! empty( $cart_item['subscrpt_max_no_payment'] )
1004 + ? (int) $cart_item['subscrpt_max_no_payment']
1005 + : $cart_item['data']->get_meta( '_subscrpt_max_no_payment' ),
1006 + // Exact plan total for split items (the entered price the split is
1007 + // divided from); null for classic split items which have no plan total.
1008 + 'split_total' => isset( $cart_item['subscrpt_split_total'] ) ? (float) $cart_item['subscrpt_split_total'] : null,
992 1009 'quantity' => (int) $cart_item['quantity'],
993 1010 )
994 1011 );
995 1012 }
@@ -1362,9 +1379,9 @@
1362 1379
1363 1380 $comment_id = wp_insert_comment(
1364 1381 array(
1365 1382 'comment_author' => 'Subscription for WooCommerce',
1366 - 'comment_content' => sprintf( 'Subscription Renewal order successfully created. order is %s', $new_order_id ),
1383 + 'comment_content' => sprintf( 'Subscription Renewal order successfully created. Order #%s', $new_order_id ),
1367 1384 'comment_post_ID' => $subscription_id,
1368 1385 'comment_type' => 'order_note',
1369 1386 )
1370 1387 );
@@ -1463,9 +1480,10 @@
1463 1480 );
1464 1481 }
1465 1482
1466 1483 if (
1467 - ! in_array( strtolower( $status ), array( 'cancelled', 'pending' ), true )
1484 + ! in_array( strtolower( $status ), array( 'cancelled', 'pending', 'completed' ), true )
1485 + && ! empty( $next_date )
1468 1486 && $next_datetime - time() <= 0
1469 1487 && (int) $default_grace_period > 0
1470 1488 ) {
1471 1489 $subscription_data['grace_period'] = array(