Support » Plugin: Advanced Woo Search » AWS is showing hidden products in search results

  • Resolved Jarkko Karhunen

    (@jarkko71k)


    I have Wholesale Suite installed on my site. This means I can have some products to be only shown to logged in wholesale customers. However, AWS is showing these hidden products to all users. When a normal user clicks on the product in the search results, nothing opens, but they shouldn’t even see those products in the search results.

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

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author ILLID

    (@mihail-barinov)

    Hello,

    You are using ‘Wholesale Prices’ plugin and activate ‘Only Show Wholesale Products To Wholesale Users’ option?

    Regards

    Yes, “Only Show Wholesale Products To Wholesale Users” is checked.

    Plugin Author ILLID

    (@mihail-barinov)

    Hi,

    I can help you with this but I need Wholesale suit for this. Can you email me to wpunitnet@gmail.com for this?

    Regards

    Actually I don’t have the whole Wholesale Suite, I have Wholesale Prices Premium, but you can get the free version here: https://wordpress.org/plugins/woocommerce-wholesale-prices/

    Plugin Author ILLID

    (@mihail-barinov)

    Yes, I have installed Wholesale Prices free plugin too. And as I understand when enabling ‘Only Show Wholesale Products To Wholesale Users’ its only reflect on what price user are see: Wholesale or regular. Its doesn’t hide any products.
    Please correct me if I wrong.

    Regards

    To hide a product from all other (not wholesale) customers, I need to select a wholesale user group in the field with 3 red dots: https://prnt.sc/ooo2vm

    This screenshot is from the view when editing a product.

    Plugin Author ILLID

    (@mihail-barinov)

    Hello,

    Please use following code snippet

    add_filter( 'aws_search_results_products', 'aws_search_results_products' );
    
    function aws_search_results_products( $products ) {
    
        $user_role = 'all';
                if ( is_user_logged_in() ) {
                    $user = wp_get_current_user();
                    $roles = ( array ) $user->roles;
                    $user_role = $roles[0];
                }
    
                $all_registered_wholesale_roles = unserialize( get_option( 'wwp_options_registered_custom_roles' ) );
                if ( ! is_array( $all_registered_wholesale_roles ) ) {
                    $all_registered_wholesale_roles = array();
                }
    
                $new_products_array = array();
    
                foreach( $products as $product ) {
    
                    $custom_fields = get_post_meta( $product['id'], 'wwpp_product_wholesale_visibility_filter' );
                    $custom_price = get_post_meta( $product['id'], 'wholesale_customer_wholesale_price' );
    
                    if ( $custom_fields && ! empty( $custom_fields ) && $custom_fields[0] !== 'all' && $custom_fields[0] !== $user_role ) {
                        continue;
                    }
    
                    if ( is_user_logged_in() && !empty( $all_registered_wholesale_roles ) && isset( $all_registered_wholesale_roles[$user_role] )
                        && get_option( 'wwpp_settings_only_show_wholesale_products_to_wholesale_users', false ) === 'yes' && ! $custom_price ) {
                        continue;
                    }
    
                    $new_products_array[] = $product;
    
                }
    
                return $new_products_array;
    
    }

    This must help you.

    Regards

    • This reply was modified 2 months, 1 week ago by  ILLID.

    Yes, this did the trick. Thank you!

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