简体   繁体   English

如何将注销的用户重定向到我的帐户页面而不是结帐页面

[英]How to redirect logged out users to my account page instead of checkout page

I am trying to redirect logged out users to my account page when they try to checkout.当他们尝试结帐时,我试图将注销的用户重定向到我的帐户页面。

I have tried this but its now working我试过这个,但它现在工作

function wpse_131562_redirect() {
    if (
        ! is_user_logged_in()
        && (is_cart() || is_checkout())
    ) {

        wp_redirect('woocommerce_myaccount_page_id'());
        exit;
    }
}
add_action('template_redirect', 'wpse_131562_redirect');

Your code can't work as there is no redirect link… Try the following instead (redirecting unlogged user from Checkout to My Account) :您的代码无法工作,因为没有重定向链接……请尝试以下操作(将未登录的用户从 Checkout 重定向到我的帐户)

add_action('template_redirect', 'unlogged_my_account_redirect');
function unlogged_my_account_redirect() {
    if ( ! is_user_logged_in() && is_checkout() && ! is_wc_endpoint_url() ) {
        wp_redirect( get_permalink( get_option('woocommerce_myaccount_page_id') ) );
        exit();
    }
}

Code goes in function.php file of your active child theme (or active theme).代码位于活动子主题(或活动主题)的 function.php 文件中。 Tested and works.测试和工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将登录用户从特定页面重定向到Woocommerce我的帐户页面 - Redirect logged in users from a specific page to Woocommerce my account page 如何将注销的用户重定向到WordPress中的其他页面 - How to redirect logged out users to different page in WordPress 如果未登录,用户将被重定向到“我的帐户”页面。如果已登录,仍会重定向。缓存重定向? - Users are redirected to My Account page if not logged in. Still redirected if logged in. Cached redirect? 禁用未登录用户的结帐页面 - Disable checkout page for not logged in users 将未登录的用户重定向到登录页面 - Redirect the not logged in users to login page Woocommerce-未登录用户的“我的帐户”页面的备用h1标题 - Woocommerce - Alternative h1 title of My Account page for not logged in users 如果未登录,将 WooCommerce 页面重定向到我的帐户页面(问题) - Redirect WooCommerce pages to My Account page if not logged in (Issue) 如何为注销和登录用户显示不同的 WordPress 首页? - How to show different WordPress front page for logged out and logged in users? 如何将未登录Wordpress网站的用户重定向到特殊的登录页面? - How can I redirect users who are not logged in to my Wordpress site to a special login page? 如何将未登录的用户重定向到 Wordpress 上的登录页面? - How to redirect non logged in users to Login page on Wordpress?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM