How can I display the days remaining before a customer's one-time purchase plan expires on my website?

Post author
Tomasz Moszyński

Hi,
How can I show my customers on my website how many days are left before their one-time purchase plan expires?
I’ve seen these posts:

https://www.memberstack.com/scripts/show-member-current-plan-details
https://docs.memberstack.com/hc/en-us/community/posts/16610228777499-How-to-display-membership-expiry-dates-to-customers-on-the-front-end-when-they-re-only-available-in-admin

…but it seems that nothing has changed in the last two years.

This should really be a basic built-in feature. My customers purchase time-limited access to trainings, and it’s important for them to know exactly when their access will expire.

Comments

3 comments

  • Comment author
    A J

    Hey Tomasz Moszyński,

    Does the memberscript you shared work for your use-case?

    If not, can you share your test mode site where I can test purchasing the one-time plan to be able to suggest how to fetch the expiry date?

    0
  • Comment author
    Tomasz Moszyński

    I coped with it this way:

    I added a field with a custom attribute: data-plan-expiry and the value from cms - PlanID from MS.

    <script>
    document.addEventListener("DOMContentLoaded", async function () {
      const ms = window.$memberstackDom;
      if (!ms) return;

      let member;
      try {
        const result = await ms.getCurrentMember();
        member = result.data;
      } catch (e) {
        console.error("Błąd getCurrentMember:", e);
        return;
      }

      if (!member || !member.planConnections) return;

      const planConnections = member.planConnections;
      const nowMs = Date.now();

      document.querySelectorAll("[data-plan-expiry]").forEach(function (el) {
        const planId = el.getAttribute("data-plan-expiry");
        if (!planId) return;

        const connection = planConnections.find(function (pc) {
          return (
            pc.planId === planId &&
            pc.active &&
            pc.payment &&
            pc.payment.cancelAtDate
          );
        });

        if (!connection) {
          el.textContent = ""; // brak zakupu → nic nie wstawiaj
          return;
        }

        const expiryMs = connection.payment.cancelAtDate * 1000;
        const diffDays = Math.ceil((expiryMs - nowMs) / (1000 * 60 * 60 * 24));

        // Wpisujemy TYLKO liczbę – bez tekstu
        el.textContent = diffDays > 0 ? diffDays : 0;
      });
    });
    </script>

    0
  • Comment author
    A J

    Thank you Tomasz Moszyński for sharing your solution.

    cc: Magnaem from Memberstack maybe we could have the memberscript handle one-time plans expiry as well.

    1

Please sign in to leave a comment.