• Resolved manesvenom

    (@manesvenom)


    Hi,

    Is it possible to add a hook before performing redirect
    wp_safe_redirect( wc_get_page_permalink( 'myaccount' ) );

    I need to add a checking if the user is visiting specific page in WooCommerce that is allowed to be viewed without login.

    I just modified the code below for the workaround:

    Check if user is visiting order received page, then skip the checking.

    if ( ! is_user_logged_in() && !is_order_received_page() && ( is_woocommerce() || is_cart() || is_checkout() ) ) {

    Regards,

    Venom

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Ramon Ahnert

    (@rahmohn)

    Hello Venom.

    I’m wondering about how to handle this kind of situation. I’m not pretty sure if an action is the best solution or a filter. Maybe I should add a hook and an option to allow specific pages. I’d really need to give that some thought.

    In the meanwhile, you can add an action that removes the redirect_not_logged_users function when a condition is true. For example, to allow Cart page to not logged in users, you can add the code below:

    
    add_action('template_redirect', function () {
       if (is_cart()) {
          remove_action('template_redirect', 'redirect_not_logged_users');
       }
    }, 5);
    
    

    Let me know if it works for you.

    I’ve created an issue in Github to do that: https://github.com/Rahmon/woo-for-logged-users/issues/7

    ??

    Thread Starter manesvenom

    (@manesvenom)

    Hi Ramon,

    Your solution is fine. I don’t need to modify your code now.

    It seems to be adding a filter and pass the redirect_url as parameter. If it returns the empty url, then it could skip performing the redirection.

    https://wordpress.stackexchange.com/questions/224416/how-to-do-action-and-get-a-return-value

    Regards,

    Venom

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hook for handling excluded page for login checking’ is closed to new replies.