SkyVerge WooCommerce Extensions

Here’s a quick question we’d gotten in a support thread: How can I add a link to “Cancel” a membership with it’s subscription to the “My Memberships” table?

Unfortunately, adding a link to cancel both a membership + it’s associated subscription isn’t really straight-forward — this is why the “cancel” action is removed in the first place when a memberships is tied to a subscription. This way, cancelling the billing record is the only way to cancel the membership (as cancelling a membership without stopping billing could cause headaches).

However, we can do something to work around this a bit: link to view the subscription associated with the user’s membership (if available) in the “My Memberships” table. The member area table actions are filterable, so you can remove or add your own actions pretty easily.

I’ve put together a simple snippet to do just that, and you can view the full snippet here.

We need it to do a few things:

  1. Get the subscriptions handler so we can check if the membership is tied to a subscription
  2. If tied to a subscription, add a new action to view the subscription in the account
  3. (Optional) rename the “View” action to “View Perks” or something similar, as we’ll now have 2 actions: “View Perks” (just “View” by default) and “View Billing”
function sv_wc_memberships_add_view_subscription_action( $actions, $user_membership ) {

    $integration = wc_memberships()->get_integrations_instance()->get_subscriptions_instance();

    if ( $integration->is_membership_linked_to_subscription( $user_membership ) ) {

        $subscription = $integration->get_subscription_from_membership( $user_membership->get_id() );
        
        $actions['view-subscription'] = array(
            'url'  => $subscription->get_view_order_url(),
            'name' => __( 'View Billing', 'my-textdomain' ),
        );
        
        $actions['view']['name'] = __( 'View Perks', 'my-textdomain' );
    }

    return $actions;
}
add_filter( 'wc_memberships_members_area_my-memberships_actions', 'sv_wc_memberships_add_view_subscription_action', 10, 2 );

You can adjust the text in this snippet for your action buttons as desired, but once this is implemented, the “My Memberships” table will now have a link to view the subscription / billing record, making it easy for the member to cancel the billing:

WooCommerce Memberships: add view subscription action

When this is clicked, it will immediately take the customer to the “View Subscription” page within the account:

WooCommerce Memberships: view subscription

This lets them update or cancel the billing record associated with the membership easily.

Published by Beka Rice

Beka manages WooCommerce product direction for SkyVerge, such as plugin roadmaps, documentation, and sales copy. She typically gets stuck with boring administrative tasks, but likes to write so she has an excuse to spend more time jamming out to anything from The Clash to Lady Gaga.

2 Comments

  1. Really useful tip here Beka.

    Should the filter now be wc_memberships_members_area_my-memberships_actions though? wc_memberships_my_account_my_memberships_actions is marked in the source as deprecated since 1.4.0

    Reply
    • Great catch Edward, thanks for that! Problems of having memorized a bunch of the hooks when writing the initial docs 😉 I’ll get this one updated here and in our snippets repo.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Error: Please enter a valid email address

Error: Invalid email

Error: Please enter your first name

Error: Please enter your last name

Error: Please enter a username

Error: Please enter a password

Error: Please confirm your password

Error: Password and password confirmation do not match