Get Woocommerce Subscription Product

I am trying to create a form for customers to fill out after they have purchased a subscription and/or when they return to the site and log in. My site has multiple subscription products and I need the form to be conditional based on which product they chose. To see whether they have an active subscription I am using this code:

$customer_orders = get_posts( array(
    'numberposts' => -1,
    'meta_key'    => '_customer_user',
    'meta_value'  => get_current_user_id(),
    'post_type'   => 'shop_subscription',
    'post_status' => array_keys( wc_get_order_statuses() ),
) );

This only returns the subscription id and status. I need to know which product was purchased with the subscription. Any help is much appreciated. Thanks!

2 Answers
2

Using the Id of a subscription you can get the subscription object :

$subscription_obj = wcs_get_subscription($sub_id);

wcs_get_subscription is a wrapper for the wc_get_order() method

Then get items of your subscription :

$items = $subscription_obj ->get_items();

Leave a Comment