How to hide WooCommerce product page for Unregistered Users?
-
I want to hide few products from Unregistered/non-login users. I am using the following code. I only want to display
$cat = 'visible';
to logout users. If a user has the link to the product and tries to open a page (the product or category I have hidden), the user should be redirected to https://www.example.com/redirect.But the code hides products from all the categories, and it does not hide the categories either.
function my_product_query( $q ) { // Is user logged in $is_logged_in = is_user_logged_in(); // Category to hide $cat = 'visible'; // Not logged in if ( !$is_logged_in ) { $q->set( 'tax_query', array( array( 'taxonomy' => 'product_cat', 'field' => 'testing1,testing2,testing3', 'terms' => $cat, // your category slug 'operator' => 'NOT IN' ) ) ); } } add_action( 'woocommerce_product_query', 'my_product_query', 10, 1 );
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to hide WooCommerce product page for Unregistered Users?’ is closed to new replies.