Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Ajax Search to respect visibility set by B2BKing
This topic contains 5 replies, has 2 voices, and was last updated by Ernest Marcinko 2 years ago.
- AuthorPosts
- April 5, 2022 at 8:23 am #37407
Hi there. We are using B2BKing and they asked us to contact you to verify if/how to respect the visibility of products based on user role. Currently the Ajax Search displays the products that are elsewhere hidden to the user.
B2BKing says: Hi Erik,
I think it probably works with the Pro version as well, but I’m not entirely sure to be honest.B2BKing works by setting the visibility in the ‘asl_query_args’ hook, via the ‘post_in’ argument. You can probably ask the developers of that plugin if that would work in the pro version as well.
April 5, 2022 at 2:42 pm #37413I found this online, from the request from B2BKing themself. But adding this to code snippets doesnt seem to do the trick. Hidden products still show up in Ajax Search.
add_filter(‘asl_query_args’, ‘asl_query_args_postin’, 10, 1);
function asl_query_args_postin($args) {
$args[‘post_in’] = is_array($args[‘post_in’]) ? $args[‘post_in’] : array();
$args[‘post_in’] = array_merge($args[‘post_in’], array(1,2,3));
return $args;
}April 5, 2022 at 3:29 pm #37422Hi,
Well, that code is for the Lite version, but it does something completely different – it limits the results to posts 1, 2 and 3 by their IDs. It is only a sample code snippet.
It should be doable via custom code, but I need to know how B2BKing sets the product visibility. If it is a custom field value, or a taxonomy term, then there very simple non-programmatical solutions.
Best,
If it uses a custom table or some other method, then all I need to know is how to check if the item is visible to the current user, using the product/post ID, and I will suggest a custom code. Let me know if you have any information about that.
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
April 5, 2022 at 3:32 pm #37424Thanks. I’ll take your answer to B2BKing 🙂
April 6, 2022 at 8:32 am #37434B2BKing replied. I have not tested the Free version of you so I dont know if that works. But this is their code,
add_filter(‘asl_query_args’, array($this, ‘asl_query_args_postin’), 10, 1);
function asl_query_args_postin($args) {
$args[‘post_in’] = is_array($args[‘post_in’]) ? $args[‘post_in’] : array();
if (!defined(‘ICL_LANGUAGE_NAME_EN’)){
$allTheIDs = get_transient(‘b2bking_user_’.get_current_user_id().’_ajax_visibility’);
} else {
$allTheIDs = get_transient(‘b2bking_user_’.get_current_user_id().’_ajax_visibility’.ICL_LANGUAGE_NAME_EN);
}
$allTheIDs = apply_filters(‘b2bking_ids_post_in_visibility’, $allTheIDs);
$currentval = $args[‘post_in’];
if (!empty($currentval) && $allTheIDs !== false){
$allTheIDs = array_intersect($allTheIDs, $currentval);
}if ($allTheIDs){
if(!empty($allTheIDs)){
$args[‘post_in’] = array_merge($args[‘post_in’], $allTheIDs);
}
}
return $args;
}April 6, 2022 at 9:00 am #37435That looks great, it will only work with the lite version, I made a change to apply for the Pro as well:
Best,add_filter('asp_query_args', array($this, 'asp_query_args_postin'), 10, 1); function asp_query_args_postin($args) { $args['post_in'] = is_array($args['post_in']) ? $args['post_in'] : array(); if (!defined('ICL_LANGUAGE_NAME_EN')){ $allTheIDs = get_transient('b2bking_user_'.get_current_user_id().'_ajax_visibility'); } else { $allTheIDs = get_transient('b2bking_user_'.get_current_user_id().'_ajax_visibility'.ICL_LANGUAGE_NAME_EN); } $allTheIDs = apply_filters('b2bking_ids_post_in_visibility', $allTheIDs); $currentval = $args['post_in']; if (!empty($currentval) && $allTheIDs !== false){ $allTheIDs = array_intersect($allTheIDs, $currentval); } if ($allTheIDs){ if(!empty($allTheIDs)){ $args['post_in'] = array_merge($args['post_in'], $allTheIDs); } } return $args; }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
The topic ‘Ajax Search to respect visibility set by B2BKing’ is closed to new replies.