Hey there guys hope your doing all good!
I’ve set up an multisite network with a shop on one site and an self build elearning site on the other site. Now I want to list all products bought by the current user on the elearning site. I’ve already tried this approach with the wcm api:
add_filter('bricks/posts/query_vars', function ($query_vars, $settings, $element_id) {
if ($element_id == 'ildiods') {
if (is_user_logged_in()) {
$user_id = get_current_user_id();
$api_url = 'https://mydomain.com/shop/wp-json/wc/v3/memberships/members?customer=' . $user_id;
$consumer_key = 'xxxxxxxxx';
$consumer_secret = 'xxxxxxxxxx';
$response = wp_remote_get($api_url, array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode($consumer_key . ':' . $consumer_secret)
)
));
if (!is_wp_error($response)) {
$memberships = json_decode(wp_remote_retrieve_body($response));
$product_ids = array();
foreach ($memberships as $membership) {
if (isset($membership->id) && !empty($membership->id)) {
$product_ids[] = $membership->plan_id;
}
}
if (!empty($product_ids)) {
$query_vars['post_type'] = 'wc_membership_plan';
$query_vars['post__in'] = $product_ids;
}
}
}
}
return $query_vars;
}, 10, 3);
The correct post Id’s were returned but I gues the query run by bricks did not switch blogs so I do not have any results and the query is empty. So how can I manipulate that the query for this specific element id switches to blog id 2?
Thank you for any help in advance!
Sincerly
KlickKlack