• Resolved vinnard

    (@vinnard)


    Hello.

    How i can check user subscribe in code?

    like this

    if ($user_sub) {

    // content for users with sub

    } else {

    // you don’t have sub

    }

    • This topic was modified 10 months, 3 weeks ago by vinnard.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author WP Swings

    (@wpswings)

    Hello,

    $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(
    ????????????'key'?? => 'wps_customer_id',
    ????????????'value' => // user id goes here,
    ????????),
    ????),
    );
    $wps_subscriptions = get_posts( $args );
    if ( ! empty( $wps_subscriptions ) && is_array( $wps_subscriptions ) ) {
    ????// if the user has subscription
    } else {
    ????// if the user does not have subscription
    }
    
    

    Thank you

    maandevs

    (@maandevs)

    $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(
    ‘key’ => ‘wps_customer_id’,
    ‘value’ => 20,
    ),
    ),
    );
    $wps_subscriptions = get_posts( $args );
    print_r($wps_subscriptions);die();

    I used the same query but returning empty array and already have active subscription. Can you please check

    maandevs

    (@maandevs)

    https://prnt.sc/pyEbrUV_TgDz please check screenshot

    Plugin Author WP Swings

    (@wpswings)

    Hello,

    There can be a chance you have hpo’s enabled woo commerce site due to the previous query is showing an empty array.

    So you need to check on your end hpos is enabled or not on your site and if hpos is enable then kindly use the below query to fetch subscriptions with respect to any user

    $args = array(
    ‘numberposts’ => -1,
    ‘type’ => ‘wps_subscriptions’,
    ‘meta_query’ => array(
    ‘relation’ => ‘AND’,
    array(
    ‘key’ => ‘wps_subscription_status’,
    ‘value’ => ‘active’,
    ),
    array(
    ‘key’ => ‘wps_customer_id’,
    ‘value’ => 20,
    ),
    ),
    );
    $wps_subscriptions = wc_get_orders( $args );

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Check user subscribe’ is closed to new replies.