I a need to create a wordpress template to collect all Woocommerce subscriptions, but I'm having trouble with the documentation. I need to know which files to import and which function to call.
Thank you in advice.
I a need to create a wordpress template to collect all Woocommerce subscriptions, but I'm having trouble with the documentation. I need to know which files to import and which function to call.
Thank you in advice.
Update: Better use
wcs_get_subscriptions()
as explained in the answer of Andrew Schultz.
As subscriptions are a custom post type, You can get all subscriptions IDs first. Then in a foreach loop you will be able to get the WC_subscription object.
global $wpdb;
// get all subscriptions IDS
$subscriptions_ids = $wpdb->get_col("
SELECT ID FROM {$wpdb->prefix}posts
WHERE post_type LIKE 'shop_subscription'
");
// Loop through subscriptions Ids
foreach($subscriptions_ids as $subscription_id){
// Get an instance of the WC_Subscription object
$subscription = new WC_Subscription( $subscription_id );
}
Then with the $subscription
object and the $subscription_id
you will be able to do what you want, using WC_Subscription
methods to get the desired data or the using subscription ID on dedicated functions.
Official developer Documentation: