简体   繁体   English

WooCommerce - 我的帐户 - 注销并重定向到主页

[英]WooCommerce - My Account - logout and redirect to Homepage

一旦用户进入他们在 WooCommerce 上的“我的帐户”页面,我希望他们退出并重定向到我的主页,而不是最终进入登录页面。

add_action('wp_logout','auto_redirect_after_logout');

function auto_redirect_after_logout(){

  wp_redirect( home_url() );
  exit();

}

If you find how to bypass WooCommerce logout confirmation, you can take this :如果您发现如何绕过 WooCommerce 注销确认,您可以采取以下措施:

function wooHook_woocommerce_logout_bypass() {
    global $wp;

    if ( isset( $wp->query_vars['customer-logout'] ) ) {
        wp_redirect( str_replace( '&', '&', 
          wp_logout_url( wc_get_page_permalink( 'hesabim' ) ) ) );
        exit;
    }
}

add_action( 'template_redirect', 'wooHook_woocommerce_logout_bypass' );

Just to add to the original answer, using exit to terminate script can stop Woocommerce from executing necessary after logout like clearing the cookies (cart items in cookies).只是为了添加到原始答案中,使用 exit 终止脚本可以阻止 Woocommerce 在注销后执行必要的操作,例如清除 cookie(cookie 中的购物车项目)。 So your best bet is using logout_url filter like this.所以你最好的选择是使用这样的logout_url过滤器。

function redirect_after_logout($logout_url, $redirect) {
    return $logout_url . '&redirect_to=' . home_url();
}
add_filter('logout_url', 'redirect_after_logout', 10, 2);

Tested in Woocommerce Version 5.4.1 ✅在 Woocommerce 版本 5.4.1 中测试 ✅

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

相关问题 如何替换我的帐户并在Woocommerce中添加登录/注销链接到菜单? - How to replace My Account and add login/logout links to menu in Woocommerce? 在 Woocommerce 我的帐户菜单中的注销项上方添加自定义项 - Add a custom item above logout item in Woocommerce my account menu 将Woocommerce我的帐户页面重定向到另一个页面 - Redirect Woocommerce my-account page to another page 将登录用户从特定页面重定向到Woocommerce我的帐户页面 - Redirect logged in users from a specific page to Woocommerce my account page 如果未登录,将 WooCommerce 页面重定向到我的帐户页面(问题) - Redirect WooCommerce pages to My Account page if not logged in (Issue) Woocommerce 如何在我的帐户页面上重定向自定义端点 - Woocommerce how to redirect a custom end point on my-account page 结帐前重定向到登录(我的帐户)并在登录后返回结帐 - Woocommerce - Redirect to login (my-account) before checkout and return to checkout after login - Woocommerce Woocommerce我的帐户导航不起作用 - Woocommerce My Account Navigation not Working 想要将我的 HTML 页面重定向到网站的主页 - Want to Redirect My HTML page to Homepage of Website WordPress:不在特定用户角色中时将主页和页面重定向到帐户页面 - WordPress: Redirect homepage and pages to account page when not in a specific user role
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM