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!