• I can’t find any technical docs, or maybe an api?

    How can I get all the current active subscriptions with PHP?

Viewing 2 replies - 1 through 2 (of 2 total)
  • It may not be the best way, but I had achieved something similar like this

    
    $subscriptionHelper = YWSBS_Subscription_Helper::get_instance();
    $users = get_users(['role' => 'customer']);
    
    foreach ($users as $user) {
        $subscriptionPosts = $subscriptionHelper->get_subscriptions_by_user($user->ID);
        $expiration = null;
        foreach ($subscriptionPosts as $subscriptionPost) {
            $subscriptionInfo = get_post_meta($subscriptionPost->ID);
            // check $subscriptionInfo['payment_due_date'][0] to see if it is after today's date
        }
    }
    

    Little late, but you can create your custom db query to list the subscribers and filter even only acitve members directly from SQL
    Assuming your database table prefix is “wp_”

    function list_all_subscriptions() {
    
    	global $wpdb;
    
    	$query= "";
    	$query .= "SELECT wp_posts.* FROM wp_posts ";
    	$query .= "INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) ";
    	$query .= "WHERE 1=1 ";
    	$query .= "AND wp_posts.post_type = 'ywsbs_subscription' ";
    	$query .= "AND ( wp_postmeta.meta_key = 'status' AND wp_postmeta.meta_value = 'active' ) "; // will filters only active members
    	$query .= "GROUP BY wp_posts.ID ";
    	$query .= "ORDER BY ID DESC";
    
    	// echo $query;
    	$subscribers = $wpdb->get_results( $query );
    }
    list_all_subscriptions();

    Hope this helps.
    Regards.

    • This reply was modified 3 years, 5 months ago by ugene.
    • This reply was modified 3 years, 5 months ago by ugene.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get all active subscriptions with PHP?’ is closed to new replies.