Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add option to display subscriptionless memberships #3058

Merged
merged 16 commits into from
Apr 22, 2024

Conversation

laurelfulford
Copy link
Contributor

@laurelfulford laurelfulford commented Apr 10, 2024

All Submissions:

Changes proposed in this Pull Request:

This PR is to work with an edge case where readers can have WooCommerce Memberships with expiration dates but without subscriptions. Because Newspack hides the Memberships tab in My Account, there's no way for readers to get information about these memberships.

In this specific case, we don't want to create associated subscriptions for these memberships because they'll send out a bunch of renewal emails. Instead, we just want a way for readers to be able to see when their memberships are expiring, so they can proactively renew them.

See: 1200550061930446-as-1206901401819708

How to test the changes in this Pull Request:

I wrote these test steps as though you'd be using different browser sessions to act as the admin and reader, but you can also use the User Switching plugin.

  1. Set up a test site with RAS set up, plus WooCommerce Memberships installed.
  2. Create two membership plans:
    • Make a membership plan that is not associated with a subscription. Set it to grant access upon "manual assignment only", and set the membership length to have a "specific length" (this can be any value, though one week, month, year is probably more realistic to test).
    • Make a membership plan that is associated with a subscription. Set up a Checkout Button block that allows you to purchase the associated subscription.
  3. Create a test reader.
  4. Manually assign the test reader the non-suscription membership plan.
  5. In an incognito window, log in as this reader in an incognito window/different browser, and go to My Account. Note that you have no way to view your Memberships -- there's no Membership tab, and if you go to Subscriptions, it says you don't have any.

image

  1. Apply this PR and run npm run build.
  2. As your WordPress Admin user, navigate to WP Admin > WooCommerce > Settings > Memberships, and scroll to the bottom; confirm you have a Reader Activation section, and a checkmark to show active Memberships that don't have associated Subscriptions. The checkmark should be unchecked.

image

  1. Check this option, and click Save.
  2. Back in your reader browser session, refresh the Subscriptions tab.
  3. Confirm that the 'No Subscriptions' message is gone, and you also get an extra table listing your non-subscription Memberships product with its expiry date:

image

  1. Still logged in as this reader, navigate to where you set up your Checkout Button block for your subscription membership product, and purchase it.
  2. Navigate back to My Account - confirm that 'Subscriptions' still says just 'Subscriptions' (and not 'My Subscription' -- normally the plugin will override that and link directly to your subscription if you have just one).
  3. Click on Subscriptions, and confirm you see your subscription listed, as well as the Memberships table:

image

  1. From the Subscription tab, click the 'View' tab next to your Membership, then click 'Manage' in the left column.
  2. Click 'Cancel' to cancel your Membership.

image

  1. Confirm that the Subscriptions tab now just says 'My Subscription' (because you don't have any active unsubscription-related memberships, it should be back at the default behaviour).
  2. As your Admin user, manually re-assign the non-sub Membership to your reader.
  3. As your reader, refresh My Account; if you're still viewing the single Subscription detail, you might need to click out of that section and back to get to the main Subscriptions list view.
  4. As the Admin user, navigate to WP Admin > WooCommerce > Settings > Memberships.
  5. Uncheck "Display memberships that don't have active subscriptions on the My Account Subscriptions tab. " and click Save.
  6. As your reader, refresh My Account and confirm the membership is gone again (to confirm it's still assigned, you can go to /my-account/members-area).

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 marked this pull request as ready for review April 10, 2024 21:06
@laurelfulford laurelfulford requested a review from a team as a code owner April 10, 2024 21:06
@laurelfulford laurelfulford added [Status] Needs Review The issue or pull request needs to be reviewed [Status] Needs Design Review labels Apr 10, 2024
@laurelfulford
Copy link
Contributor Author

@thomasguillot @kevinzweerink This one's kind of "it is what it is" visually, but I'd appreciate your thoughts on hiding the 'Cancel' button from the main Memberships table. Normally it shows in the list, but it seemed like extra clutter, and it wasn't consistent with how the Subscriptions list looked, when both were displaying.

(I'd also appreciate any feedback on little things we can improve!).

@thomasguillot
Copy link
Contributor

Can we hide the "next bill on" column since it's not applicable?

@laurelfulford
Copy link
Contributor Author

Can we hide the "next bill on" column since it's not applicable?

@thomasguillot Oooo, good call! I just pushed an update -- here's what it looks like without:

image

Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

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

@laurelfulford works well and with very clean code! Just a few minor suggestions below.

Adding the extra option in WooCommerce settings makes sense, but in practice we usually try not to add our own options into the WooCommerce settings UI. I think we should try to reimplement this new setting in the Newspack > Reader Activation > Advanced Settings wizard page. I'm okay with doing this as a separate follow-up PR so it doesn't block this one, though.

public static function get_memberships_without_subs() {
if ( function_exists( 'wc_memberships_get_user_active_memberships' ) ) {
$customer_id = \get_current_user_id();
$memberships_info = wc_memberships_get_user_active_memberships( $customer_id );
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this is not currently throwing any errors for me, but it's something we've run into occasionally, so this is a good practice to get into the habit of:

Suggested change
$memberships_info = wc_memberships_get_user_active_memberships( $customer_id );
$memberships_info = \wc_memberships_get_user_active_memberships( $customer_id );

If you're working in a PHP file that has a namespace (as this one does), when calling any global function, it's a good idea to prefix it with \. This tells PHP to look for this function in the global namespace. If you don't include the \ prefix, then PHP will first look for the function in the current namespace and then fall back to global if it doesn't exist in the current namespace. I've seen instances where this can cause fatal errors, so adding the \ sidesteps that whole issue and also makes the code a little clearer in a namespaced file (even if it's not required to avoid errors like in this case).

The exception to this rule is internal PHP functions, so if you can find the function in the PHP manual, you don't need to specify a namespace (global or otherwise) for it. In my code editor internal PHP functions are helpfully highlighted in a different color than other functions:

Screenshot 2024-04-16 at 1 03 47 PM

You also don't need to prefix the function name when checking whether it exists (like function_exists) as this will check for the function in every namespace including the global one, unless you pass a specific namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TIL -- nice! I didn't realize the purpose of the \, I figured it had something to do with namespaced/not namespaced, but didn't realize what it actually did under the hood.

@laurelfulford
Copy link
Contributor Author

Thanks for this, @dkoo! This was all very helpful!

I made the code corrections in 44698b9, and then took a swing at moving the option into the Reader Activation advanced settings in d130fae.

It should now appear with the other Membership settings there, and, when the Memberships plugin isn't enabled, it shouldn't appear:

image

(It's also off by default like the original, which my screenshot doesn't really convey!)

Just let me know if it'd be better to roll back this bit and focus on the original set of changes, or if there's anything else that looks amiss -- thanks!

@laurelfulford laurelfulford requested a review from dkoo April 16, 2024 23:54
Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

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

Thanks for the changes! Looks good and works well!

@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 labels Apr 18, 2024
@laurelfulford laurelfulford merged commit aa493c9 into release Apr 22, 2024
7 checks passed
@laurelfulford laurelfulford deleted the hotfix/display-memberships-no-subs branch April 22, 2024 19:02
matticbot pushed a commit that referenced this pull request Apr 22, 2024
## [3.6.13](v3.6.12...v3.6.13) (2024-04-22)

### Bug Fixes

* add option to display subscriptionless memberships ([#3058](#3058)) ([aa493c9](aa493c9))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 3.6.13 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Apr 22, 2024
# [3.7.0-alpha.7](v3.7.0-alpha.6...v3.7.0-alpha.7) (2024-04-22)

### Bug Fixes

* add option to display subscriptionless memberships ([#3058](#3058)) ([aa493c9](aa493c9))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 3.7.0-alpha.7 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released on @alpha released [Status] Approved The pull request has been reviewed and is ready to merge [Status] Needs Design Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants