admin管理员组

文章数量:1278653

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.

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.

Share Improve this question asked Jan 22, 2018 at 19:01 WP CoderWP Coder 251 silver badge5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 4

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.

本文标签: Woocommerce Membership Expiry Date