In WooCommerce I am redirecting non logged users to My Account page when they visit any WooCommerce page. But after user login (in My Account page) when I try to visit that same woocommerce page it’s redirect me to My Account page.
But when I visit any other WooCommerce pages its working perfect.

I am using this code for this purpose:

<?php
    if ( !is_user_logged_in() ) {
        if(is_woocommerce() || is_shop() || is_cart() || is_checkout())  {

            wp_redirect( get_permalink( get_option('woocommerce_myaccount_page_id')) );
            exit();
        }
    }
?>

I think the problem is that it stores something in cache or another redirection issue, so when user visit same url it’s redirected to My Account when is logged in.

How can I solve this problem.

Thanks

Read more here: Redirect WooCommerce pages to My Account page if not logged in (Issue)


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: