How i can display end date subscribe for user ? I have id user and i need date for end subscribe
I try use $WC_Subscription and wcs_get_users_subscriptions($user_id) but this method throws an error.
How I can use $WC_Subscription?
How i can display end date subscribe for user ? I have id user and i need date for end subscribe
I try use $WC_Subscription and wcs_get_users_subscriptions($user_id) but this method throws an error.
How I can use $WC_Subscription?
Copyright © 2021 Jogjafile Inc.
First,
wcs_get_users_subscriptions($user_id)is not a method but a function.WC_Subscriptionis the main Class for subscriptions.The main issue in your approach is that
wcs_get_users_subscriptions($user_id)function return an array of user subscriptions, but not the subscription object itself, as a user can have multiple subscriptions.To get the end date from a
WC_Subscriptionobject, you will useget_date('end')method.Based on this answer here is the correct way to get, for a user, his subscription's end date, without throwing errors.
foreachloop to iterate through the user subscriptions:current()orreset()functions to get the subscription object, for only one subscription: