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?


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.