How to redirect back to the original CMS page after payment completion? Answered

Post author
Marko Guzvic

Can you set up the redirect after the payment to the page from which you were redirected to checkout? It’s CMS pages to which I want to redirect.

Comments

3 comments

  • Comment author
    Julian Galluzzo

    I've never tried this with paid plans, but it may work https://webflow.com/made-in-webflow/website/dont-redirect-on-login-memberstack

    0
  • Comment author
    Marko Guzvic

    Yup this is exactly what I needed! I just edited the script to delay it for 5 seconds so I can show the success page before redirect.
    On every page:

    <script>
    // sets the url of the page you’re on for redirecting back to it
    localStorage.setItem(‘locat’, location.href);
    </script>

    On the page from which you’d send users from:

    <script>
    // Vérifie si la page a déjà été rechargée
    if (!localStorage.getItem(‘reloaded’)) {
      // Enregistre le fait que la page a été rechargée
      localStorage.setItem(‘reloaded’, ‘true’);
      // Recharge la page
      window.location.reload();
    } else {
      // Supprime l’indicateur de rechargement de la page du localStorage
      // pour que la page puisse être rechargée la prochaine fois
      localStorage.removeItem(‘reloaded’);
    }
    </script>
    <script>
    // Check if ‘locat’ exists in localStorage and is not the current page
    var locat = localStorage.getItem(‘locat’);
    if (locat && locat !== location.href) {
      // Wait for 5 seconds (5000 milliseconds) before redirecting
      setTimeout(function() {
        window.location = locat;
      }, 5000);
    } else if (locat && locat === location.href) {
      // If ‘locat’ is set on the current page, redirect to the previous ‘locat’
      var previousLocat = localStorage.getItem(‘previousLocat’);
      if (previousLocat && previousLocat !== location.href) {
        window.location = previousLocat;
      } else {
        // Handle the case where there’s no previous ‘locat’ or it’s the current page
        alert(‘No previous locat found for redirection’);
      }
    } else {
      // If ‘locat’ is not set, you can handle this case accordingly
      // For example, you can redirect to a default page or display a message
      alert(‘Redirect not possible’);
    }
    </script>

    Powered by chatGpt 😀
    I don’t think alerts are necessary but it works like this for me 🙂

    Thank you Julian!

    0
  • Comment author
    Julian Galluzzo

    No problem at all, and perfect!!

    0

Please sign in to leave a comment.