Display button only for paid plan user not working

Hello and thank you for helping in advance.

I know virtually nothing about coding but copied something I found on this forum earlier in order to basically show one button for users with an active pricing plan and one thing for everything else.

Unless I am delusional, this worked at one point in time. Nothing - as far as I am aware, has changed since today and two days ago on the site which should have caused this. I removed some community pages since we did not use them as well as some other pages, however, I don’t see how this would be relevant. Below is the code in question:

import wixUsers from ‘wix-users’ ;
let user = wixUsers . currentUser ;

$w . onReady (()=> {
user . getPricingPlans (). then (( plans ) => {
if ( plans . length > 0 ) {
let firstPlan = plans [ 0 ];
let today = new Date ();

      **if**  ( today . getTime () >=  firstPlan . expiryDate . getTime ()) { 
    $w ( '#button49' ). show (); 
    $w ( '#button37' ). hide (); 
      }  **else**  { 
    $w ( '#button49' ). hide (); 
    $w ( '#button37' ). show (); 
      } 
    }  **else**  { 
        $w ( '#button49' ). show (); 
        $w ( '#button37' ). hide (); 
    } 
}) 

})

Is the code broken and was I simply mistaken earlier? Could something else have caused this?

I see no error in your code, but I really don’t like working Date() from vanilla JavaScript.

I advise you to installing the Moment.JS NPM Package and using it, is really easier to work with. Here is how to do it.

Your code would look like this:

import wixUsers from "wix-users"
import moment from "moment"

let user = wixUsers.currentUser

$w.onReady(async () => {
    let plans = await user.getPricingPlans() //Just made it easier to read
  
    if (plans.length > 0) {
        let firstPlan = plans[0]
        let today = moment().format()
        let expiryDate = moment(firstPlan.expiryDate).format()

        if (today >= expiryDate) {
            $w("#button49").show()
            $w("#button37").hide()
        } else {
            $w("#button49").hide()
            $w("#button37").show()
        }
    } else {
        $w("#button49").show()
        $w("#button37").hide()
    }
})