• Resolved shahil14

    (@shahil14)


    Hello,I have a variable subscription product with 3 Plan attributes (Starter|Professional|Enterprise) and 2 Billing Period attributes (Monthly|Annually). I am trying to get the Plan name and Billing Period for the active subscriptions for the logged in user.
    How do I get the active variable subscription product details for the current user in php?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author WP Swings

    (@wpswings)

    Hello,

    Thank you for trying our plugin,

    wps_sfw_subscription_interval
    wps_sfw_subscription_number

    You will find the billing type(day/week/month/year) and the billing period from meta data using these meta keys in the subscription

    Thank you

    Thread Starter shahil14

    (@shahil14)

    Hello thanks for replying. I am currently using the below code to get the active subscription product details but it won’t work. Can you recommend any suggestions?

    $args = array(
    'numberposts' => -1,
    'post_type' => 'wps_subscriptions',
    'post_status' => 'wc-wps_renewal',
    'meta_query' => array(
    'relation' => 'AND',
    array(
    'key' => 'wps_subscription_status',
    'value' => 'active',
    ),
    array(
    'relation' => 'AND',
    array(
    'key' => 'wps_parent_order',
    'compare' => 'EXISTS',
    ),
    array(
    'key' => 'wps_customer_id',
    'value' => get_current_user_id(),
    'compare' => '==',
    ),
    ),
    ),
    );
    $wps_subscriptions = get_posts( $args ); // returns nothing even though I have 1 active subscription
    foreach ( $wps_subscriptions as $key => $value ) {
    $subscription_id = $value->ID;
    // do something here
    }
    Plugin Author WP Swings

    (@wpswings)

    Hello,

    The code which you are using is only work if your woocommerce site is hpos disable and as you mention you are getting blank value that means your site have enable hpos enable from woocommerce in that case query will be changes and here we sharing query in case hpos

    $args = array(
    ????????‘return’?? => ‘ids’,
    ????????‘type’?? => ‘wps_subscriptions’,
    ????????‘meta_query’ => array(
    ????????????‘relation’ => ‘AND’,
    ????????????array(
    ????????????????‘key’?? => ‘wps_subscription_status’,
    ????????????????‘value’ => ‘active’,
    ????????????),
    ????????????array(
    ????????????????‘relation’ => ‘AND’,
    ????????????????array(
    ????????????????????‘key’?? => ‘wps_parent_order’,
    ????????????????????‘compare’ => ‘EXISTS’,
    ????????????????),
    ????????????????array(
    ????????????????????‘key’?? => ‘wps_customer_id’,
    ????????????????????‘value’ => get_current_user_id(),
    ????????????????????‘compare’ => ‘=’,
    ????????????????),
    ????????????),
    ????????),
    ????);
    ????$wps_subscriptions = wc_get_orders( $args );

    Thread Starter shahil14

    (@shahil14)

    Hello,
    I tried that but I am getting output like this: {“refunds”:null,”order_type”:”wps_subscriptions”}

    I want the subscription id, subscription name, etc. How can I get them?

    Plugin Author WP Swings

    (@wpswings)

    Hello,

    Please connect to our support team for personal help, as we have tested same code on our local and it works fine

    Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.