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;
}
}
Related Posts:
- Fatal Error when installing woocommerce despite upgrading
- Adding an action within a function that is being called by add_filter
- Pass custom Checkout field value to Stripe gateway in WooCommerce
- woocommerce fail to replace template string in email title [closed]
- Set a specific default stock quantity on all WooCommerce new products
- Shipping Location based on IP (Geolocation)
- How to set a minimum length for username in Woocommerce? [closed]
- How to get term name with link for specific ids
- woocommerce “publish “”product”” webhook
- Creating woocommerce product using WordPress REST API
- WooCommerce Product Page css
- Image is not displayed in overridden woocommerce email
- remove categories from product
- Woocommerce: custom loop in product tabs breaks reviews tab
- woo commerce get all orders item given category
- Add Stripe Connect data to wc_stripe_payment_request
- WooCommerce get default shipping rate & conditions
- Using WooCommerce for payments only?
- Programatically Remove Item from Cart Not Working – Needs Page Refresh
- WooCommerce – Stock in Decimals, Using Quantity Intervals with Unique Prices [closed]
- Set default value field meta_Value [closed]
- Woocommerce Product Import Automation
- WooCommerce Cart Link based on Cookie Values
- Woocommerce is_shop not on page slug? [closed]
- WooCommerce – Trigger Checkout Form Validation
- Debugging why featured images have stopped showing in WooCommerce on the homepage [closed]
- WooCommerce minimum order amount for specific country excluding local pickup [closed]
- DELETE WooCommerce Order data from database
- woocommerce list product by id
- Woocommerce Login Redirect to old domain
- CF7 Ajax isn’t working when called inside WooCommerce “woocommerce_before_add_to_cart_button” hook [closed]
- Show Content On below single product with specific category
- How to change a WooCommerce Subscription Deposit and Monthly Payment? [closed]
- How to output woocommerce products to a page, style and modify the html structure
- how to scrolling image on single product page
- How to display WooCommerce product tag names on home and category pages
- Specifically Link To the “Leave a review” part of product page? [closed]
- Variation Swatches for WooCommerce – too many variations
- Woocommerce pre_get_posts query variation meta data not working
- Can’t hide product attributes with css on WooCommerce Product Page
- Updating product image
- Split in 2 columns add to cart button and variable forms
- Images not uploading on product page of woocommercr
- How to access WC()->cart in CF7 hook wpcf7_special_mail_tags
- How to integrate e-transfers with checkout in WooCommerce
- Manual Admin Orders search for billing_company
- Woocommerce to get restaurant table numbers in the checkout fields from the url
- Send all emails to Shop Manager along with admin
- Snippet to copy product affiliate link to a custom field
- Woocommerce Checkout Page Total Price Inside Google Pay Script
- UX Builder not loading for product description edits
- I need help with storefront theme shop page
- How to get rid of variations with unspecified attributes
- Woocommerce shop page not showing all products
- Wrong Billing Information in WC_Checkout->get_checkout_fields(‘billing’)?
- How to display two different custom taxonomy terms on a WooCommerce single product page
- Registration roles
- Change password notification email
- How to show price update date in product single page?
- why my price is not showing while adding new product?
- How to send Woocommerce Customer Details (Name, Email and Phone Number) to Admin upon signup
- Sending billing details via POST request to an API
- how can my customers view their purchased products history like an invoice in a specific page on WordPress
- How do I make my products on the homepage responsive?
- How to get users data from wordpress woocomerce database to display
- Simple thing esc_url query
- Tax exclusive if coupon applied else tax inclusive in items
- WooCommerce Registration, Sync User, Billing and Shipping info
- Woocommerce on Subdirectory
- Change WooCommerce state and city checkout fields to dropdowns related to the chosen country
- Select all product woocommerce
- Woocommerce REST API: creating variations
- How to customize product at cart page
- WooCommerce Storefront site-header padding
- WooCommerce: How can I add a certain product to the cart and redirect to the cart from a non-shop page?
- How to check which shortcode is using my template?
- Update products with curl (bash)
- woocommerce: when adding or removing items to cart , it takes cart a few seconds to read changes?
- How to get woocommerce integration instance?
- Create woocommerce order on new user registration
- How to put a date range in a virtual/downloadable product? [closed]
- When to use a child theme for WooCommerce Storefront?
- Redirect whole website or pages to /wp-admin in wordpress
- Changing sale price programmatically, but it’s not shown on front-end
- Woocommerce shows empty columns [closed]
- Product atributes in title of order (not in description)
- How to create custome pdf file of my invioice in wordpress
- How to get sub items of parent menu item?
- WordPress and WooCommerce How to Assign Attribute Based Pricing
- Storefront Child Theme show product attribute [closed]
- How to remove slug from Product category URL in Woocommerce
- Removing ‘woocommerce-no-js’ class from body
- url rewrite doesn’t load woocommerce product
- Can I remove WooCommerce specific product categories from shop managers?
- Fetch products with filter by similar categories at same time
- Trying query woocommerce product order by menu order and stock status
- editing product page template – getting template for related products not working
- Disable Woocommerce Block Editor
- Woocommerce backend sorting product drag drop by menu_order to date
- Conflict between Woocommerce Booking + Woocommerce Product Options [closed]