2

I'm trying to display a user's Subscriptions within their WooCommerce dashboard. I am able to do this, but I also want to add some additional fields related to the Subscription (title, next renewal date, expiration date, and current subscription status). But I'm having a hard time pulling in the data. Here is what I have so far:

add_action( 'woocommerce_account_dashboard', 'my_dashboard_subscriptions' );
function my_dashboard_subscriptions() {
    $user_id = get_current_user_id();
    echo '<h3>Current Subscriptions</h3>';

    // Get all of their subscriptions
    $subscriptions = get_posts( array(
        'numberposts' => -1,
        'post_type'   => 'shop_subscription', // Subscription post type
        'post_status' => 'wc-active', // Active subscription
        'order' => 'ASC',
        'meta_key'    => '_customer_user',
        'meta_value'  => $user_id,
    ) );

    // Displaying list in an html table
    echo "<table class='shop_table subscription_list'>
        <tr>
            <th>Title</th>
            <th>Status</th>
            <th>Renew Date</th>
            <th>End Date</th>
            <th>Subscriber</th>
        </tr>
            ";
    // Going through each current customer orders
    foreach ( $subscriptions as $subscription ) {
        $subscription_id = $subscription->ID; // subscription ID
        $subscr_meta_data = get_post_meta($subscription->ID);
        $customer_name = $subscr_meta_data['_billing_first_name'][0] . ' ' . $subscr_meta_data['_billing_last_name'][0];

        echo "</tr>
                <td>$subscription_title - #$subscription_id</td>
                <td>$renew_date</td>
                <td>$end_date</td>
                <td>$sub_status</td>
                <td>$customer_name</td>
            </tr>";
    }
    echo '</table>';

}

I am trying to add the Subscription's title, current status, renewal date, and expiration date.

But most methods that I've tried, to grab those fields, it didn't work. Any ideas?

1
  • Garconis, did you solve this issue? I have the exact same question.
    – user658182
    Aug 17 '18 at 21:39