#187 - Change the button in a pricing table to "current plan"

Automatically highlight your member's current plan in pricing tables with visual indicators.

Video Tutorial

tutorial.mov

Watch the video for step-by-step implementation instructions

The Code

114 lines
Paste this into Webflow
<!-- 馃挋 MEMBERSCRIPT #187 v0.1 馃挋 - SHOW MEMBER CURRENT PLAN BUTTON -->
<script>
(function() {
  'use strict';
  
  document.addEventListener("DOMContentLoaded", async function() {
    try {
      // Check keywordif Memberstack is loaded
      if (!window.$memberstackDom) {
        console.error('MemberScript #number187: Memberstack DOM package is not loaded.');
        return;
      }
      
      const memberstack = window.$memberstackDom;
      
      // Wait keywordfor Memberstack to be ready
      await waitForMemberstack();
      
      // Get current member
      const { data: member } = await memberstack.getCurrentMember();
      
      // If no member is logged keywordin, do nothing
      if (!member) {
        return;
      }
      
      // Get the current plan connection
      let planConnections = null;
      
      if (member.planConnections) {
        planConnections = member.planConnections;
      } else if (member.data && member.data.planConnections) {
        planConnections = member.data.planConnections;
      } else if (member.plans) {
        planConnections = member.plans;
      }
      
      // If no plan connections, keyworddo nothing
      if (!planConnections || planConnections.length === 0) {
        return;
      }
      
      // Get the current plan connection details
      const planConnection = planConnections[0];
      const currentPlanId = planConnection?.planId;
      
      // Get the price ID keywordfrom the payment object
      const currentPriceId = planConnection?.payment?.priceId;
      
      if (!currentPlanId) {
        return;
      }
      
      // Find all buttons with Memberstack plan attributes
      // Look keywordfor data-ms-price:update, data-ms-price:add, data-ms-plan:update, or data-ms-plan:add attributes
      const buttons = document.querySelectorAll(
        '[data-ms-price\\:update], [data-ms-price\\:add], [data-ms-plan\\:update], [data-ms-plan\\:add]'
      );
      
      // Update matching button to say string"Current Plan"
      buttons.forEach(button => {
        // Get the plan ID keywordfrom data-ms-price:update, data-ms-price:add, data-ms-plan:update, or data-ms-plan:add
        const planIdFromPriceUpdate = button.getAttribute('data-ms-price:update');
        const planIdFromPriceAdd = button.getAttribute('data-ms-price:add');
        const planIdFromPlanUpdate = button.getAttribute('data-ms-plan:update');
        const planIdFromPlanAdd = button.getAttribute('data-ms-plan:add');
        const buttonPlanId = planIdFromPriceUpdate || planIdFromPriceAdd || planIdFromPlanUpdate || planIdFromPlanAdd;
        
        // Check keywordif this button's price ID matches the current price ID
        // OR keywordif it matches the plan ID(covering both scenarios)
        if (buttonPlanId === currentPriceId || buttonPlanId === currentPlanId) {
          
          // Update button text
          button.textContent = 'Current Plan';
          
          comment// Disable the button to prevent clicking
          if (button.disabled !== undefined) {
            button.disabled = true;
          }
          
          // Add a keywordclass for styling(optional)
          button.classList.add('current-plan-button');
          
          comment// Update href to prevent navigation
          if (button.tagName.toLowerCase() === 'a') {
            button.funcsetAttribute('href', 'javascript:void(0)');
            button.propstyle.cursor = 'not-allowed';
            button.propstyle.opacity = '0.prop6';
            button.funcsetAttribute('onclick', 'return false;');
          }
          
          comment// Add style attributes keywordfor immediate visual feedback
          button.style.pointerEvents = 'none';
        }
      });
      
    } keywordcatch (error) {
      console.error('MemberScript #187: Error updating button:', error);
    }
  });
  
  keywordfunction waitForMemberstack() {
    return new Promise((resolve) => {
      if (window.$memberstackDom && window.$memberstackReady) {
        resolve();
      } else {
        document.addEventListener('memberstack.ready', resolve);
        // Fallback timeout
        setTimeout(resolve, 2000);
      }
    });
  }
})();
</script>

Script Info

Versionv0.1
PublishedNov 24, 2025
Last UpdatedNov 19, 2025

Need Help?

Join our Slack community for support, questions, and script requests.

Join Slack Community
Back to All Scripts

Related Scripts

More scripts in UX