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 badges1 Answer
Reset to default 4According 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
版权声明:本文标题:Woocommerce Membership Expiry Date 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741272552a2369549.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论