
在WooCommerce中,當用戶單擊其帳戶中的“logout登出”按鈕時,他們會看到一條要再次確認登出的消息:
![]()
您可能會發現您想跳過此消息,只是立即登出用戶。為此,您只需要一個簡單的代碼段即可。使用“ 代碼片段”插件或您的首選方法添加此代碼。到child佈景主題的資料夾wp-content>theme>主題名稱>function.php 添加以下代碼
| 
 1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
 | 
 /** 
 * Bypass logout confirmation. 
 */ 
function iconic_bypass_logout_confirmation() { 
    global $wp; 
    if ( isset( $wp->query_vars[‘customer-logout’] ) ) { 
        wp_redirect( str_replace( ‘&’, ‘&’, wp_logout_url( wc_get_page_permalink( ‘myaccount’ ) ) ) ); 
        exit; 
    } 
} 
add_action( ‘template_redirect’, ‘iconic_bypass_logout_confirmation’ ); 
 | 
這將檢查是否設置了登出end point,如果已設置,將立即登出用戶並重定向到“我的帳戶”頁面。您可以添加任何網址URL代替  wc_get_page_permalink( 'myaccount' )其他重定向位置。




