将登录用户从特定页面重定向到 Woocommerce 我的帐户页面 [英] Redirect logged in users from a specific page to Woocommerce my account page
问题描述
在 Woocommerce 中,我试图找到一种解决方案来检查用户是否已登录自定义页面,如果是,则将用户重定向到我的帐户"页面.
In Woocommerce I am trying to find a solution for checking if a user is logged in on custom page and if so, redirect user to "My Account" page.
对此的任何帮助表示赞赏.
Any help on this is appreciated.
推荐答案
尝试以下操作,您将用您的真实页面 ID 替换 'some-page'
,蛞蝓或名称.该代码会将已定义的特定页面的登录用户重定向到我的帐户页面:
Try the following, where you will replace 'some-page'
by your real page ID, slug or name. The code will redirect for a defined specific page logged in users to the my account 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 文件中.经测试有效.
Code goes in function.php file of your active child theme (or active theme). Tested and works.
对于 2 个页面,您将使用:is_page( array( 'some-page', 'some-other' ) )
For 2 pages you will use: is_page( array( 'some-page', 'some-other' ) )
这篇关于将登录用户从特定页面重定向到 Woocommerce 我的帐户页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!