PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 2.2.0
Subscriptions for WooCommerce with Stripe Recurring Payments v2.2.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 +29 -7 1.11.0 → 2.2.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' ),
@@ -495,12 +503,16 @@
495 503
496 504 // Allow modification of split payment arguments
497 505 $split_payment_args = apply_filters( 'subscrpt_split_payment_args', $split_payment_args, $order_item, $product );
498 506
507 + // Own the subscription from the order's customer, not the current user.
508 + $parent_order = wc_get_order( $order_item->get_order_id() );
509 +
499 510 $args = array(
500 511 'post_title' => 'Subscription',
501 512 'post_type' => 'subscrpt_order',
502 513 'post_status' => $split_payment_args['post_status'],
514 + 'post_author' => $parent_order ? (int) $parent_order->get_customer_id() : get_current_user_id(),
503 515 );
504 516 $subscription_id = wp_insert_post( $args );
505 517 wp_update_post(
506 518 array(
@@ -508,9 +520,10 @@
508 520 'post_title' => "Subscription #{$subscription_id}",
509 521 )
510 522 );
511 523 // Check if this is a split payment subscription
512 - $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';
513 526 $max_payments = $product->get_meta( '_subscrpt_max_no_payment' );
514 527
515 528 $comment_content = '';
516 529 $activity_type = '';
@@ -973,10 +986,13 @@
973 986 foreach ( $cart_items as $key => $cart_item ) {
974 987 $product = $cart_item['data'];
975 988 if ( $product->is_type( 'simple' ) && isset( $cart_item['subscription'] ) ) {
976 989 $cart_subscription = $cart_item['subscription'];
977 - $type = ucfirst( $cart_subscription['type'] );
978 - $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 );
979 995
980 996 $recurrs[ $key ] = array_merge(
981 997 $price_data,
982 998 array(
@@ -983,9 +999,14 @@
983 999 'trial_status' => ! is_null( $cart_subscription['trial'] ),
984 1000 'start_date' => self::start_date( $cart_subscription['trial'] ),
985 1001 'next_date' => self::next_date( ( $cart_subscription['time'] ?? 1 ) . ' ' . $cart_subscription['type'], $cart_subscription['trial'] ),
986 1002 'can_user_cancel' => $cart_item['data']->get_meta( '_subscrpt_user_cancel' ),
987 - '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,
988 1009 'quantity' => (int) $cart_item['quantity'],
989 1010 )
990 1011 );
991 1012 }
@@ -1358,9 +1379,9 @@
1358 1379
1359 1380 $comment_id = wp_insert_comment(
1360 1381 array(
1361 1382 'comment_author' => 'Subscription for WooCommerce',
1362 - '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 ),
1363 1384 'comment_post_ID' => $subscription_id,
1364 1385 'comment_type' => 'order_note',
1365 1386 )
1366 1387 );
@@ -1459,9 +1480,10 @@
1459 1480 );
1460 1481 }
1461 1482
1462 1483 if (
1463 - ! in_array( strtolower( $status ), array( 'cancelled', 'pending' ), true )
1484 + ! in_array( strtolower( $status ), array( 'cancelled', 'pending', 'completed' ), true )
1485 + && ! empty( $next_date )
1464 1486 && $next_datetime - time() <= 0
1465 1487 && (int) $default_grace_period > 0
1466 1488 ) {
1467 1489 $subscription_data['grace_period'] = array(