I have a client, Primal Vinyasa, which I’ve built an extensive membership site for. The top product worth promoting and we want to retain is the Monthly Subscription. To encourage retention, it’s worthwhile to figure out all the pain points customers have. For the monthly subscriber just wanting to access their member content, signing in via the My-Account page can be frustrating as this doesn’t get them their content, but rather, the WooCommerce My Account Dashboard. Even with modifying the dashboard template via the theme so that there’s a big ol’ obvious link to the content, they still get distracted with all the account management buttons:
What we wanted to do is instead to redirect them to our new content starting page, as seen below:
I’ve also included a “hide introduction” checkbox on this page so that after watching/reading it once, a user can click the box to hide that section. Through the usage of LocalSession, the browser will remember their preference. I’ll write a blog post on that later.
Skyverge, the developers of the WooCommerce Membership plugin have a post about how to Create a “My Memberships” section shortcode with WooCommerce Memberships: https://www.skyverge.com/blog/create-memberships-section-shortcode-woocommerce-memberships/. However, because the Primal Vinyasa website also lists products for sale that don’t have anything to do with online video content, I wanted to make sure that the customers who are buying rose oil will still go to the traditional WC dashboard.
I found an article over at https://memberfix.rocks/redirect-membership-woocommerce/ that helped get me started down the path and UX I wanted. The code they provided had some errors in it, and it was intended for logic for multiple membership landing pages. What you’ll find below is my modifications for our Primal Monthly Subscriber membership. I hope it’s useful
<?php
function mfix_show_memberships_details ($curr_user_id) {
if ( is_admin() ) {
return;
}
$customer_memberships = wc_memberships_get_user_memberships( $curr_user_id );
$former_subscriber = [];
$active_subscriber = [];
foreach ( $customer_memberships as $customer_membership ) {
$membership_plans = $customer_membership -> get_plan() -> get_name();
$membership_plans_array[] = $customer_membership->get_plan()->get_name();
$membership_plans_status = $customer_membership->get_status();
$membership_plans_status_array[] = $customer_membership->get_status();
if (($membership_plans == "Full Access Subscription") && ($membership_plans_status == "cancelled")) {$former_subscriber[] = "former_subscriber";}
if (($membership_plans == "Full Access Subscription") && ($membership_plans_status == "expired")) {$former_subscriber[] = "former_subscriber";}
if (($membership_plans == "Full Access Subscription") && ($membership_plans_status == "active")) {$active_subscriber[] = "active_subscriber";}
}
if(!empty($active_subscriber)){
$current_stats = "active_subscriber";
return $current_stats;
exit();
}
else if (!empty($former_subscriber)){
$current_stats = "former_subscriber";
return $current_stats;
exit();
}
else {
$current_stats = "potential_member";
return $current_stats;
exit();
}
}
function mfix_custom_user_redirect( $redirect, $user ) {
$username = $user->user_login;
$curr_user = get_user_by('login',$username);
$curr_user_id = $curr_user->ID;
$current_stats = mfix_show_memberships_details ($curr_user_id);
if( $current_stats == "active_subscriber" ) {
// $redirect = "/start-here/";
$redirect = "/content-index/";
}
if( $current_stats == "former_subscriber" ) {
$redirect = "/my-account/";
}
return $redirect;
}
add_filter( 'woocommerce_login_redirect', 'mfix_custom_user_redirect', 10, 2 );
I placed this into a functionality plugin, because even if the theme changes, we’ll still want this same user experience.
I hope this helps others who might be wondering how to create an improved user experience for their membership sites.
Hi,
Anyway to make it work for the wp-login instead of the WooCommerce login.
Thanks
Karen
What’s the use case here? The snippet is for front end customers, who hopefully aren’t typing in “mysite.com/wp-login.php” into their browsers.
Hello! I can’t have it work, I save, no error msg but when I play my scenarios I’m not being redirected! I tried to put the membership Name or slug, in both cases it’s not workin!
Hello Ramy. First of all, are you sure that the code is firing? You could add in an console.log message to confirm this.
Have you used query monitor? Where are you saving this to? A child theme’s function.php file?
Hello Gray,
I did try in a snippet, in the custom plugin I created. In the console, I’m not seeing any error related to the code you provided. The only think I did it’s to change the membership name (I also tried using the snippet)
What I meant by checking the console is whether you are sure that the code is even firing. So for example right after the code in your custom plugin’s file, write something like:
?>
This way you know that your site is even processing the code snippet. See https://scoutapm.com/blog/tutorial-log-to-console-in-php for more detailed information on these pathways for problem solving.
Hey Gray, good stuff!
Thanks for the shoutout to MemberFix, I appreciate it. :)
Vic
Founder – MemberFix
Thank you for the code. It works great for our single membership level.
Thank you. Worked really well.