How to redirect free plan users to upgrade page instead of default access denied URL and hide pages from all users? Answered

Post author
Hamza Nasim

I am new here and I have a question. When my "Free Plan" users try to access the "Paid Plan" content, how can I redirect them to a different URL than the default access denied URL? In this case, I want "Free Plan" users to go to an "Upgrade" page and non-users to go to the "Join" page(the default access denied URL). I hope my question makes sense.

Comments

6 comments

  • Comment author
    Chukwudi

    There are two different ways you can achieve this:

    Option 1: Set the access denied page for the Paid Plan to the URL of the Upgrade Plan page and then, create another gated content for the Upgrade Plan page and this time, set the access denied URL to the Join page. This way, if non-users try to access the Paid plan page, they get redirected to the Upgrade page which instantly redirects them to the Join Page, on the other hand, if Free plan users try to access the paid plan page, then only end up on the Upgrade plan page.

    Option 2: Delete the gated content setup you have for the page Paid Plan content, as well as the gated content data-ms-content attribute you have on the paid plan page, so as to avoid conflicts, then place the code below before the closing </body> section of the paid plan content page.

    <script>
    window.$memberstackDom.getCurrentMember().then((member) => {
    if (member.data) {
    const planConnections = member.data["planConnections"];
    if (planConnections && planConnections.length > 0) {
    let hasPaidPlan = false;

    for (const plan of planConnections) {
    if (plan.type !== "FREE") {
    hasPaidPlan = true;
    break;
    }
    }

    if (hasPaidPlan) {
    window.location.href = 'URLForPaidPlanUsersGoesHere'; // Change this to your Paid Plan User Redirect page URL
    }
    else {
    window.location.href = 'URLForFreePlanUsersGoesHere'; // Change this to your Free Plan User Redirect page URL
    }
    }
    }
    else {
    window.location.href = 'URLForNonUsersGoesHere'; // Change this to your Non User Redirect page URL
    }
    });
    </script>
    0
  • Comment author
    Hamza Nasim

    I guess the Option1 is the more sensible solution to go for. 

    Thanks it works perfectly. Big thanks for the help.

    New question, is there a way to gate a page from both paid and free users. I want to hide the /join page from both of them.

    0
  • Comment author
    Chukwudi

    Your setup would look like this:

    0
  • Comment author
    Hamza Nasim

    Will it prevent the paid users too?

    0
  • Comment author
    Chukwudi

    So sorry I missed that 🤦, please ignore my previous response.

    In that case, you just need to place the code below before the closing </body> section of the Join page. What this code does is redirect members who try to access the Join page to the URL you set here 

    RedirectURLGoesHere<script>
    window.$memberstackDom.getCurrentMember().then((member) => {
    if (member.data) {
    window.location.href = 'RedirectURLGoesHere'; // Change this to your Redirect page URL
    }
    });
    </script>
    0
  • Comment author
    Hamza Nasim

    You seem to have answer to everything haha 😀. Thank you.

    It works thank you man you saved the day!

    0

Please sign in to leave a comment.