Skip to content

Commit 6380768

Browse files
committed
Show Expired status for monetize subscriptions past their end date
1 parent a3021c3 commit 6380768

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

client/dashboard/me/billing-monetize-subscriptions/monetize-item.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ export const MonetizeSubscriptionTerms = ( {
2020
return <>{ __( 'Never expires' ) }</>;
2121
}
2222

23+
// Check if end_date is in the past
24+
const endDate = new Date( subscription.end_date );
25+
const isExpired = endDate < new Date();
26+
27+
// Show "Expired" for past dates
28+
if ( isExpired ) {
29+
return <>{ __( 'Expired' ) }</>;
30+
}
31+
32+
// Show renewal or expiry for future dates
2333
return (
2434
<>
2535
{ subscription.renew_interval === null
@@ -29,7 +39,7 @@ export const MonetizeSubscriptionTerms = ( {
2939
dateStyle: 'long',
3040
} ),
3141
} )
32-
: // translators: %(siteUrl)s is the URL of the site. %(date)s is the date the subscription renews. . Format is LL (e.g. January 1, 2020).
42+
: // translators: %(amount)s is the renewal price, %(date)s is the date the subscription renews. Format is LL (e.g. January 1, 2020).
3343
sprintf( __( 'Renews at %(amount)s on %(date)s' ), {
3444
amount: formatCurrency( Number( subscription.renewal_price ), subscription.currency ),
3545
date: formatDate( new Date( Date.parse( subscription?.end_date ?? '' ) ), locale, {

client/me/purchases/membership-item/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,26 @@ export const MembershipTerms = ( { subscription }: { subscription: MembershipSub
1616
return <>{ translate( 'Never expires' ) }</>;
1717
}
1818

19+
// Check if expired
20+
const endDate = moment( subscription.end_date );
21+
const isExpired = endDate.isBefore( moment() );
22+
23+
if ( isExpired ) {
24+
return <>{ translate( 'Expired' ) }</>;
25+
}
26+
1927
return (
2028
<>
2129
{ subscription.renew_interval === null
2230
? translate( 'Expires on %(date)s', {
2331
args: {
24-
date: moment( subscription.end_date ).format( 'LL' ),
32+
date: endDate.format( 'LL' ),
2533
},
2634
} )
2735
: translate( 'Renews at %(amount)s on %(date)s', {
2836
args: {
2937
amount: formatCurrency( Number( subscription.renewal_price ), subscription.currency ),
30-
date: moment( subscription.end_date ).format( 'LL' ),
38+
date: endDate.format( 'LL' ),
3139
},
3240
} ) }
3341
</>

0 commit comments

Comments
 (0)