• Resolved LS

    (@lsterling03)


    I don’t know if this is the right forum for this, but I can’t find a Woocommerce Subscriptions forum anywhere else. Does anyone know how I can output the products for a given subscription if I know the subscription ID?

    I have tried $subscriptions = wcs_get_subscription(1341); where 1341 is the subscription ID, but that doesn’t return the products within the subscription. It only gives me information about the subscription itself.

    I appreciate any help to point me in the right direction. I’m trying to figure this out without having to hire a developer. Thanks!

    • This topic was modified 8 years, 5 months ago by LS.
    • This topic was modified 8 years, 5 months ago by LS.
Viewing 1 replies (of 1 total)
  • Thread Starter LS

    (@lsterling03)

    Ok, I solved this problem with this code:

    $subscription = wcs_get_subscription(1341);
    	
    	foreach ( $subscription->get_items() as $item_id => $item ) {
    		$_product  = apply_filters( 'woocommerce_subscriptions_order_item_product', $subscription->get_product_from_item( $item ), $item );
    		
    		if ( apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {
    	
    			if ( $_product && ! $_product->is_visible() ) {
    				echo esc_html( apply_filters( 'woocommerce_order_item_name', $item['name'], $item ) );
    			} else {
    				echo wp_kses_post( apply_filters( 'woocommerce_order_item_name', sprintf( '<a href="%s">%s</a>', get_permalink( $item['product_id'] ), $item['name'] ), $item ) );
    			}
    
    		}
    	}
Viewing 1 replies (of 1 total)
  • The topic ‘Get list of subscription products for a subscription ID?’ is closed to new replies.