You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WooCommerce登出端点失效求助:无法退出WordPress站点

Troubleshooting the WooCommerce Logout Loop Issue

Hey there, I totally feel your pain—3 hours stuck on a logout loop is no fun, especially when you’ve already ruled out extra plugins, switched to a default theme, and confirmed the endpoint is set up. Since manually calling wp_logout() works, that tells us the core logout functionality is intact; the problem lies in how WooCommerce is handling the redirect after logout. Let’s walk through the most likely fixes:

1. Flush WordPress Rewrite Rules

WooCommerce’s account endpoints (like customer-logout) rely on WordPress’s rewrite rules to work properly. Sometimes these rules get out of sync, causing the redirect loop. Here’s how to fix it:

  • Go to Settings → Permalinks in your WordPress dashboard.
  • You don’t need to change anything—just click the Save Changes button. This forces WordPress to refresh its rewrite rules.
  • If that doesn’t work, you can temporarily add this code to your child theme’s functions.php file, visit your site once, then remove it:
    flush_rewrite_rules();
    

2. Override the Logout Redirect Hook

It’s possible a leftover hook (from a previous plugin or custom theme code) is messing with the logout redirect. Let’s force a specific redirect to bypass this:
Add this code to your child theme’s functions.php file:

add_action('woocommerce_logout_redirect', 'custom_force_logout_redirect', 999);
function custom_force_logout_redirect($redirect_url) {
    // Replace with the URL you want users to land on after logout (e.g., home page)
    return home_url('/');
}

Test the logout button again—if it works, you’ll know the issue was with the existing redirect hook. You can then dig through your theme’s files to find and remove the conflicting code.

Incorrect cookie settings can cause persistent login sessions even after clicking logout. Open your wp-config.php file and look for lines like these:

define('COOKIE_DOMAIN', 'yourdomain.com');
define('COOKIE_PATH', '/');

If these are set incorrectly (e.g., your site uses www.yourdomain.com but the cookie domain is set to yourdomain.com, or vice versa), it can prevent the logout cookie from being cleared. Try commenting out these lines temporarily (add // at the start) and test logout again.

4. Double-Check WooCommerce Endpoint Settings

Even though you mentioned setting the default customer-logout endpoint, it’s worth verifying:

  • Go to WooCommerce → Settings → Advanced → Account endpoints.
  • Make sure the "Logout" field is exactly customer-logout (no leading/trailing slashes, no typos).
  • Save the settings, then flush rewrite rules again (as in step 1).

Since wp_logout() works manually, the key here is fixing the redirect flow that WooCommerce uses. Start with the rewrite rules first—they’re the most common culprit for endpoint-related issues.

内容的提问来源于stack exchange,提问作者Sio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:46:05