• Resolved WP Ninja

    (@sameernxb)


    Hi,

    We are using your plugin Advance Woo Search which works fine. We are having one issue and that is we want to remove specific product category products from search when a user is logged in to the website. A kind of restricted product search for logged in customers. I am using this article to hide specific products of a category. It works partially and there is an issue I have to give all combinations of search terms to prevent the product from appearing in the search which is very frustrating. Is there an easy way of doing it. Here is my code, the problem is to hide one product Freya I have to give 3 combination for search terms one is Fre, Frey and Freya. Is there a better way of doing it. We have large number of products which we are looking to hide of a product category. The best solution would to simply exclude the products of a specific taxonomy which is not based on user search terms.

    function aws_custom_search_terms($terms) {
    // Store the terms in a global variable
    global $aws_search_terms;
    $aws_search_terms = $terms;
    return $terms;
    }

    add_filter('aws_search_terms', 'aws_custom_search_terms');

    function aws_custom_search_query_array($query) {

    // Use the global variable to get the terms
    global $aws_search_terms;

    $exclude_array = array(
    'fre' => array(1922),
    'frey' => array(1922),
    'freya' => array(1922),
    );
    $exclude_ids_array = array();

    if ($aws_search_terms) {
    foreach ($exclude_array as $term => $ids) {
    $term_arr = explode(' ', $term);
    $exclude = false;

    if ($term_arr && count($term_arr) === count($aws_search_terms)) {
    foreach ($term_arr as $term_i) {
    if (array_search($term_i, $aws_search_terms) !== false) {
    $exclude = true;
    } else {
    $exclude = false;
    }
    }
    }

    if ($exclude) {
    $exclude_ids_array = array_merge($exclude_ids_array, $ids);
    }
    }
    }

    if (!empty($exclude_ids_array)) {
    global $wpdb;

    $taxonomies = implode(',', $exclude_ids_array);

    $query['exclude_products'] = " AND ( id NOT IN (
    SELECT $wpdb->posts.ID
    FROM $wpdb->term_relationships
    JOIN $wpdb->posts
    ON ( $wpdb->term_relationships.object_id = $wpdb->posts.post_parent OR $wpdb->term_relationships.object_id = $wpdb->posts.ID )
    WHERE $wpdb->term_relationships.term_taxonomy_id IN (
    SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id IN ({$taxonomies})
    )
    ))";
    }

    return $query;

    }
    add_filter('aws_search_query_array', 'aws_custom_search_query_array');

    Does the premium version of the plugin support the option of excluding products of a specific category only for logged in customers not for all of them?. Looking forward to your response.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author ILLID

    (@mihail-barinov)

    Hi,

    Yes, with the pro plugin version you can create a filter based on the current user role and hide some products if the user is logged in. Example – https://prnt.sc/-yA_KsDR_jLB

    But for now it is not possible to set additional rules based on the current search query. It is something that I’m planning to add in the next plugin releases.

    Regards

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.