I am currently developing a WordPress project and I am using WooCommerce with WooCommerce Subscriptions plugin to offer subscriptions to my users. I need help on how to get the quantity of a subscription in PHP.
I am using this code to get subscription but I can not retrieve quantity:
$subscriptions = wcs_get_subscriptions( array(
'customer_id' => get_current_user_id(),
'subscription_status' => 'wc-active',
'order_by' => 'DESC',
'subscriptions_per_page' => - 1
) );
When a user purchases a subscription, the user can select the quantity of subscriptions. So I need to get the value of this field:
2
Answers
Here is my working code try this
And if you want get all post_status subscription then use this
Thanks
Your code is correct and
wcs_get_subscriptions()
is the right and best way to get customer active subscriptions.But you have missed a something after your code to get the customer subscription item quantity (code commented):
Tested and works.