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
$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
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 );