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?

1 Answer
1

use 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.

Leave a Reply

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