![](/img/trans.png)
[英]Woocommerce - Alternative h1 title of My Account page for not logged in users
[英]Redirect logged in users from a specific page to Woocommerce my account page
在Woocommerce中,我試圖找到一種解決方案來檢查用戶是否在自定義頁面上登錄,如果是,請將用戶重定向到“我的帳戶”頁面。
在這方面的任何幫助表示贊賞。
您應該使用$ _SESSION。 這有助於您驗證用戶是否在頁面上登錄。
if(isset($_SESSION['UserID'])){
header('Location: [url]');
}
使用Wordpress:
$current_user = wp_get_current_user();
if ( 0 != $current_user->ID ) {
$template = get_page_template_slug($post->ID);
if($template == "your_custom_template_name"){
wp_redirect( wp_login_url() )
}
}
請嘗試以下操作,您將在其中用真實的頁面ID,段或名稱替換'some-page'
。 該代碼會將登錄用戶的已定義特定頁面重定向到“我的帳戶”頁面:
add_action('template_redirect', 'specific_logged_in_redirect');
function specific_logged_in_redirect() {
if ( is_page('some-page') && is_user_logged_in() ) {
wp_redirect( get_permalink( get_option('woocommerce_myaccount_page_id') ) );
exit();
}
}
代碼進入您的活動子主題(或活動主題)的function.php文件中。 經過測試和工作。
對於2頁,您將使用: is_page( array( 'some-page', 'some-other' ) )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.