Skip to content

Conversation

@laurelfulford
Copy link
Contributor

All Submissions:

Changes proposed in this Pull Request:

This PR hides trashed subscriptions from the My Account view.

If you only have trashed subscriptions, it hides the Subscriptions menu all together.

See: NPPM-2442

How to test the changes in this Pull Request:

  1. Start on a test site with RAS set up
  2. Set up a subscription product that can be purchased multiple times by the same reader (just to make testing easier), and add a Checkout button block
  3. In an incognito window, run through a purchase of your subscription with the credit card 4000 0000 0000 0341 (which will result in a failed payment).
  4. After the transaction fails, go to 'My Account', and note the trash sub:
CleanShot 2025-12-09 at 15 15 41
  1. Apply this PR and run npm run build.
  2. In the incognito window, refresh the page; confirm you don't have any subscriptions listed, and there isn't a Subscription menu item (so the typical reader wouldn't get to this screen).
CleanShot 2025-12-09 at 15 16 17
  1. Go back and try to buy the subscription again, this time using a successful test card.
  2. Go back to My Account, and confirm you have a single My Subscription; when you click on it it should show your one subscription details:
CleanShot 2025-12-09 at 15 27 23
  1. Purchase a second subscription and confirm you get the Subscriptions menu item with a list as the top level in My Account, and that only non-trashed subs are shown (you can also mess with the subscriptions, cancelling them, etc.). All of them should show, unless they are trashed:
CleanShot 2025-12-09 at 15 28 51
  1. Lastly, as the admin manually trash all but one subscription and make sure you're back to the view in step 8 (if you just refresh the /subscriptions page as the user, you'll still see the list with one item, but the navigation should say My Subscription and just go to the remaining non-trashed one).

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@laurelfulford laurelfulford requested a review from a team as a code owner December 9, 2025 23:31
@laurelfulford laurelfulford added the [Status] Needs Review The issue or pull request needs to be reviewed label Dec 9, 2025
@laurelfulford laurelfulford changed the title Fix/hide trashed subscriptions fix: hide 'trashed' subscriptions from My Account Dec 9, 2025
@miguelpeixe miguelpeixe self-requested a review December 12, 2025 14:18
Copy link
Member

@miguelpeixe miguelpeixe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tested well, but I think we can go for a simpler approach. The user subscription list and "Subscriptions/My Subscription" button rely on wcs_get_users_subscriptions(), which supports a hook.

Something like this should be enough:

add_filter(
	'wcs_get_users_subscriptions',
	function( $subscriptions ) {
		if ( function_exists( 'is_account_page' ) && is_account_page() ) {
			$subscriptions = array_filter(
				$subscriptions,
				function( $subscription ) {
					return ! $subscription->has_status( 'trash' );
				}
			);
		}
		return $subscriptions;
	},
	10
);

@github-actions github-actions bot added the [Status] Needs Changes or Feedback The issue or pull request needs action from the original creator label Dec 12, 2025
@laurelfulford
Copy link
Contributor Author

Oh, that's so much nicer - thanks @miguelpeixe! 🙌

I left a couple pieces of the original code in:

  • I noticed when you just had My Subscription in the menu it didn't highlight when you clicked on it, so that's been fixed
  • I tweaked the styles of buttons when they're in notices to just look like regular links - they were displaying full size before and sticking out of the bottom. I only saw this kind of message + button when I visited /my-account/subscriptions/ when no subscriptions were actually showing - a reader's not going to get to that but it was bugging me 😆

Copy link
Member

@miguelpeixe miguelpeixe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for revising! 🙌

@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed [Status] Needs Changes or Feedback The issue or pull request needs action from the original creator labels Dec 15, 2025
@laurelfulford laurelfulford merged commit e759378 into trunk Dec 15, 2025
8 checks passed
@laurelfulford laurelfulford deleted the fix/hide-trashed-subscriptions branch December 15, 2025 18:06
@github-actions
Copy link

Hey @laurelfulford, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Approved The pull request has been reviewed and is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants