Issue with Private Products Not Appearing in AJAX Search or Search Results
-
Hello Support Team,
I am encountering an issue with private products on my website. I added the following code to my functions.php to allow the ‘customer’ role to access private products and product variations:
/* Enable the ‘customer’ role to read private products and variations */
function allow_customer_to_read_private_products_and_variations() {
// Ensure the ‘customer’ role exists
$role = get_role(‘customer’);
if ($role) {
// Add the capabilities to read private products and product variations
$role->add_cap(‘read_private_products’); // Read private products
$role->add_cap(‘read_private_product_variations’); // Read private product variations
}
}
add_action(‘init’, ‘allow_customer_to_read_private_products_and_variations’);
While the customers with the ‘customer’ role can access the private products (as they have the necessary capability), the private products do not show up in the AJAX search or on the search result page.
Could you please assist in resolving this issue? The expectation is for private products to appear in the AJAX search and search result page for users with the appropriate customer role and capabilities.
Thank you for your support!
Hello,
Apologies, but we’re not familiar with how this code is intended to function or how to resolve the issue. Since you’re working with custom code, fixing additional customizations falls outside the scope of our theme support. We hope you understand the limitations of our support.
Best regards,
Please guide me on how to enable private products in the search result for customer role.
-
This reply was modified 1 year, 5 months ago by
Amit.
Hello,
Unfortunately, this feature is not available by default. To add more functionality, you will need to use a third-party plugin that fits your needs. Please note that we have not tested any plugins related to this with our theme, so we cannot make any guarantees. You can check out this plugin as an option but at your own risk: [Products Visibility by User Roles]( https://woocommerce.com/products/products-visibility-by-user-roles/ ).
Best regards,