Sometimes we need to set up private online shop. The easiest and fastest way to set up an online shop is to set up WordPress with WooCommerce. In WordPress, we can easily add a functionality that prevents guest users to access the products/shop page. Here is the code which needs to be in functions.php in theme files.
function guest_user_redirect() {
if (! is_user_logged_in() && (is_woocommerce() || is_cart() || is_checkout())) {
wp_redirect(home_url());
exit;
}
}
add_action('template_redirect', 'guest_user_redirect');
Comments
Post a Comment