I've a members' only subscription site, where the member can only have one active subscription, and I need to be able to get the status of the subscription.
I've been through all the documentation and found the
wcs_get_users_subscriptions()
function, which returns an array of all subscription products for the given user, in reverse date order (ie, latest is always first).
I settled on this code which, whilst it works, I know is absolutely the wrong way to do it:
$subs = wcs_get_users_subscriptions( $user_id );
$subs = (object) array_shift( $subs );
$subs = (object) $subs->data;
$return = $subs->status;
Does anyone know the right way?
I've a members' only subscription site, where the member can only have one active subscription, and I need to be able to get the status of the subscription.
I've been through all the documentation and found the
wcs_get_users_subscriptions()
function, which returns an array of all subscription products for the given user, in reverse date order (ie, latest is always first).
I settled on this code which, whilst it works, I know is absolutely the wrong way to do it:
$subs = wcs_get_users_subscriptions( $user_id );
$subs = (object) array_shift( $subs );
$subs = (object) $subs->data;
$return = $subs->status;
Does anyone know the right way?
Share Improve this question edited Jun 13, 2018 at 16:21 Peter HvD asked Jun 5, 2018 at 16:17 Peter HvDPeter HvD 1,1211 gold badge6 silver badges16 bronze badges1 Answer
Reset to default 12use this code
$users_subscriptions = wcs_get_users_subscriptions($user_id);
retrieve the data using foreach
foreach ($users_subscriptions as $subscription){
if ($subscription->has_status(array('active'))) {
echo $subscription->get_id();
}
}
There is some function to access subscription data. like get_id(),get_date('end') (to get last date of subscription ).
I hope its help you well.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744819836a4595547.html
评论列表(0条)