This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Ajax Search to respect visibility set by B2BKing

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Ajax Search to respect visibility set by B2BKing

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #37407
    erikleirdalerikleirdal
    Participant

    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.

    #37413
    erikleirdalerikleirdal
    Participant

    I 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;
    }

    #37422
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    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.
    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.

    #37424
    erikleirdalerikleirdal
    Participant

    Thanks. I’ll take your answer to B2BKing 🙂

    #37434
    erikleirdalerikleirdal
    Participant

    B2BKing 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;
    }

    #37435
    Ernest MarcinkoErnest Marcinko
    Keymaster

    That looks great, it will only work with the lite version, I made a change to apply for the Pro as well:

    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;
    }
Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Ajax Search to respect visibility set by B2BKing’ is closed to new replies.