admin管理员组文章数量:1130349
I’m building a shop in WooCommerce and wish to restrict access & viewing of the shop to logged in members only.
I don’t mind having links to the shop visible (such as in the nav bar), as clicking the shop link, or trying to directly access a shop item would check if the user is logged in, and if not, then redirected to ‘My Account’ to create an account.
Any there any options available to me via plugins or the functions.php?
Secondly, I found an answer the thread below, which is almost exactly what I want: Make WooCommerce pages accessible for logged in users only
I made the suggested changes, but I got an error. Would the error be that I have to insert information unique to my WP install in the following line:
add_action(‘template_redirect’, ‘wpse_131562_redirect’);
I’m building a shop in WooCommerce and wish to restrict access & viewing of the shop to logged in members only.
I don’t mind having links to the shop visible (such as in the nav bar), as clicking the shop link, or trying to directly access a shop item would check if the user is logged in, and if not, then redirected to ‘My Account’ to create an account.
Any there any options available to me via plugins or the functions.php?
Secondly, I found an answer the thread below, which is almost exactly what I want: Make WooCommerce pages accessible for logged in users only
I made the suggested changes, but I got an error. Would the error be that I have to insert information unique to my WP install in the following line:
add_action(‘template_redirect’, ‘wpse_131562_redirect’);
Share
Improve this question
edited Apr 13, 2017 at 12:37
CommunityBot
1
asked Mar 6, 2016 at 3:11
MattMatt
231 silver badge3 bronze badges
1 Answer
Reset to default 2I just tested this and it will work. Drop this into your functions.php and whenever a user who isn't logged in tries to access a WooCommerce template such as the shop, product pages, cart, or checkout it will redirect them to the WordPress login page.
add_action( 'template_redirect', 'redirect_users_not_logged_in' );
/**
* Redirect non logged-in users to login page when they try to access any
* woocommerce template including the cart or checkout page.
*
* @author Joe Dooley - Developing Designs
* @return void
*
*/
function redirect_users_not_logged_in() {
if ( ! is_user_logged_in() && ( is_woocommerce() || is_cart() || is_checkout() ) ) {
auth_redirect();
exit;
}
}
I’m building a shop in WooCommerce and wish to restrict access & viewing of the shop to logged in members only.
I don’t mind having links to the shop visible (such as in the nav bar), as clicking the shop link, or trying to directly access a shop item would check if the user is logged in, and if not, then redirected to ‘My Account’ to create an account.
Any there any options available to me via plugins or the functions.php?
Secondly, I found an answer the thread below, which is almost exactly what I want: Make WooCommerce pages accessible for logged in users only
I made the suggested changes, but I got an error. Would the error be that I have to insert information unique to my WP install in the following line:
add_action(‘template_redirect’, ‘wpse_131562_redirect’);
I’m building a shop in WooCommerce and wish to restrict access & viewing of the shop to logged in members only.
I don’t mind having links to the shop visible (such as in the nav bar), as clicking the shop link, or trying to directly access a shop item would check if the user is logged in, and if not, then redirected to ‘My Account’ to create an account.
Any there any options available to me via plugins or the functions.php?
Secondly, I found an answer the thread below, which is almost exactly what I want: Make WooCommerce pages accessible for logged in users only
I made the suggested changes, but I got an error. Would the error be that I have to insert information unique to my WP install in the following line:
add_action(‘template_redirect’, ‘wpse_131562_redirect’);
Share
Improve this question
edited Apr 13, 2017 at 12:37
CommunityBot
1
asked Mar 6, 2016 at 3:11
MattMatt
231 silver badge3 bronze badges
1 Answer
Reset to default 2I just tested this and it will work. Drop this into your functions.php and whenever a user who isn't logged in tries to access a WooCommerce template such as the shop, product pages, cart, or checkout it will redirect them to the WordPress login page.
add_action( 'template_redirect', 'redirect_users_not_logged_in' );
/**
* Redirect non logged-in users to login page when they try to access any
* woocommerce template including the cart or checkout page.
*
* @author Joe Dooley - Developing Designs
* @return void
*
*/
function redirect_users_not_logged_in() {
if ( ! is_user_logged_in() && ( is_woocommerce() || is_cart() || is_checkout() ) ) {
auth_redirect();
exit;
}
}
本文标签: WooCommerce pages accessible to logged in members only
版权声明:本文标题:WooCommerce pages accessible to logged in members only 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749027476a2305331.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论