Techwordpress

How to Make WooCommerce pages accessible for logged in users only

How can I redirect users, who are not logged in, to another page if they try to access a WooCommerce page?

function wpse_131562_redirect() {
    if (
        ! is_user_logged_in()
        && (is_woocommerce() || is_cart() || is_checkout())
    ) {
        // feel free to customize the following line to suit your needs
        wp_safe_redirect( wc_get_page_permalink( 'myaccount' ) );
        exit;
    }
}
add_action('template_redirect', 'wpse_131562_redirect');

Related Articles

Back to top button
Enable Notifications OK No thanks