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!

  • Can you please send more information? how the subscription is saved? – Cesar Henrique Damascena Jul 31 '17 at 22:49
  • @CesarHenriqueDamascena I am using the woocommerce subscription plugin – Cameron Aug 1 '17 at 22:55
  • I don't know this plugin, but maybe one way of doing this, is if you do a WP_Query searching for the subscription that you get with the user, and see if you can get the attribute that links the subscription with the product. – Cesar Henrique Damascena Aug 1 '17 at 23:22

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();

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.