Make WC pages accessible for logged in users only

Make WC pages accessible for logged in users only

Short Intro:

How to make WooCommerce pages accessible for logged-in users only without using a third-party plugin.

Problem:

Non-logged-in users can visit shop pages.

Solution:

Copy this code and paste on theme editor> functions.php
function wpse_131562_redirect() {
if (
! is_user_logged_in()
&& (is_woocommerce() || is_cart() || is_checkout())
) {
// feel free to customize the following line to suit your needs
wp_redirect( get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ) );
exit;
}
}
add_action('template_redirect', 'wpse_131562_redirect');

Contact details

More solutions

by ilias

You're using JetFormBuilder and want to make sure users are at least 18 years old based on their birthday input.

by ilias

Roweij Spices wanted to have a filter that can choose number of products display per pagination

by ilias

This article will show you how to add dynamic code to your templates using the Elementor Shortcode widget and custom PHP code.