$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>WooCommerce pages accessible to logged in members only|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

WooCommerce pages accessible to logged in members only

matteradmin9PV0评论

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
Add a comment  | 

1 Answer 1

Reset to default 2

I 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;
    }
}
Post a comment

comment list (0)

  1. No comments so far