get sub id by vm id
This commit is contained in:
parent
3a6eb3b9cb
commit
b6cc128c5f
@ -437,6 +437,51 @@ function federated_needs_provision_subscriptions(){
|
||||
return array_map('get_subscription_id', $posts);
|
||||
}
|
||||
|
||||
//Get by VM ID
|
||||
add_action('rest_api_init', 'federated_route_get_subscription_by_vm_id');
|
||||
|
||||
function federated_route_get_subscription_by_vm_id(){
|
||||
//register routes here
|
||||
register_rest_route(
|
||||
'federated-rest/v1',
|
||||
'get-subscription-id-by-vm-id',
|
||||
array(
|
||||
'methods' => 'POST',
|
||||
'callback' => 'federated_get_subscription_by_vm_id',
|
||||
'permissions_callback' => 'check_federated_permissions'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function federated_get_subscription_by_vm_id($request){
|
||||
$vm_id = $request['vm_id'];
|
||||
|
||||
$args = array(
|
||||
'numberposts' => -1,
|
||||
'post_type' => 'shop_subscription',
|
||||
'post_status' => 'wc-active',
|
||||
'meta_key' => 'vm_id',
|
||||
'meta_value' => $vm_id
|
||||
);
|
||||
|
||||
$posts = get_posts($args);
|
||||
$output = array();
|
||||
|
||||
foreach($posts as $post) {
|
||||
$subscription_id = get_subscription_id($post);
|
||||
$subscription_vm_id = get_field('vm_id', $subscription_id);
|
||||
|
||||
if($subscription_vm_id == $vm_id) {
|
||||
$output['subscription_id'] = $subscription_id;
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
$output['subscription_id'] = 0;
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
//Shared Functions
|
||||
function get_subscription_id($subscription){
|
||||
return $subscription->ID;
|
||||
|
Loading…
Reference in New Issue
Block a user