I’m hoping to be able to get the expiry date for the current user but can’t seem to sort out how to do that. I’ve checked the documentation and see that there are some functions that allow for data to be pulled but none include the expiry date. The following gets basically everything but dates…

wc_memberships_get_user_memberships()

Any idea how I would go about doing this? Either I’m missing something obvious or it’ll need to be done with a custom query.

1 Answer
1

According to the documentation, wc_memberships_get_user_memberships() returns a list of WC_Memberships_User_Membership objects.

The WC_Memberships_User_Membership class has a get_end_date() method that will return the expiry date.

So you should be able to do something like this:

// Get memberships for the current user.
$memberships = wc_memberships_get_user_memberships();

// Verify that they have some memberships.
if ( $memberships ) {
  foreach( $memberships as $membership ) {
    // Print the expiration date in mysql format.
    echo $membership->get_end_date();
  }
}

The mysql date format is the default, but you can also use something like $membership->get_end_date( 'Y-m-d H:i:s' ) to have custom formatting or $membership->get_end_date( 'timestamp' ) to get the timestamp.

Leave a Reply

Your email address will not be published. Required fields are marked *