All guides

Require a WooCommerce account before adding to cart: a plugin you can build today

· 4 min read

WooCommerce lets anyone add products to the cart and check out as a guest. For most stores, that is the right default. For competition sites, wholesale stores, and members-only shops, it creates a real problem: you need to know who the customer is before they can start the buying process, not after.

WooCommerce's account settings let you disable guest checkout, but that stops guests at the checkout page after they have already added items to the cart, possibly browsed for several minutes, and started filling in address fields. The right place to block a guest is the Add to Cart button itself, before any cart interaction happens.

What one build gives you

  • Admin settings page under WooCommerce > Settings for enabling the restriction and customising the guest message
  • Replacement of the Add to Cart button with a styled notice and Login and Register links for guests
  • Validation hook that blocks programmatic add-to-cart attempts by guests with a wc_add_notice error
  • Works on simple, variable, and grouped WooCommerce product types

What it does not do

  • Per-product control: the restriction applies to all products or none
  • Role-based access: any logged-in user can add to cart regardless of their role
  • Restricting product page visibility to logged-in users only
  • Automatic redirect back to the original product page after a guest logs in
  • Account approval workflow for new registrations

WP Force Login does these. This covers the part most sites use.

The prompt

Loads into the composer so you can edit it first. Nothing is built, and nothing is charged, until you send it.

Build a WordPress plugin for WooCommerce that prevents guests from adding products to the cart. Add a settings page under WooCommerce > Settings > Guest Restrictions with two fields: an enable or disable toggle and a custom message field with the default text 'Please create an account or log in to add products to your cart'. On all WooCommerce product pages, when the current visitor is not logged in, replace the Add to Cart button with a styled div containing the custom message and two inline links labeled 'Log in' and 'Create account' that point to the WooCommerce login and registration page URLs. Also hook into woocommerce_add_to_cart_validation to reject any guest add-to-cart requests that arrive through other means such as quick-add buttons or direct URL parameters, calling wc_add_notice with an error and returning false. Show nothing extra to logged-in customers.

Build this pluginAbout 55 credits · the free plan includes enough for one

Why blocking at checkout is too late

When guest checkout is disabled in WooCommerce, a guest can still browse, add products to their cart, and proceed well into the checkout flow before hitting a wall. For a standard retail store, this is a minor friction point. For a competition or prize draw site, it is a real problem: if someone has already gone through several steps before discovering they need an account, a significant share of them will not bother.

Replacing the Add to Cart button for guests makes the requirement visible immediately. The guest sees the message on the product page and understands what is needed. The registration form is one click away instead of buried at the end of a checkout process they cannot complete.

What the plugin delivers

A Steem build for this job adds a settings page under WooCommerce > Settings > Guest Restrictions with two fields: a toggle to enable or disable the restriction site-wide, and a text field for the message shown to guests. The default message is set to something reasonable out of the box.

On product pages, the Add to Cart button is replaced for guests with a styled box containing the custom message and links to the WooCommerce login and registration pages. Logged-in customers see the normal Add to Cart button and are completely unaffected.

How to install and use it

Paste the prompt below into Steem. The plugin builds as a downloadable zip. Install it under Plugins > Add New > Upload Plugin, then go to WooCommerce > Settings > Guest Restrictions.

Enable the restriction, adjust the message text if you want something specific to your store, and save. Guests on any product page will see the notice instead of the Add to Cart button from that point on.

When this is most useful

Competition and prize draw sites are the clearest case. Regulations typically require verified entrants, and WooCommerce's default guest flow works against that requirement entirely. Blocking at the Add to Cart stage means no one accidentally enters without an account on record.

Wholesale stores that require account approval before a customer can order also benefit. This plugin handles the first step: requiring a login before the cart is touched. A second small build can add an account approval workflow, putting new registrations into a pending state until a site admin manually approves them.

Questions

Does WooCommerce not already have a way to require an account?
It does, under WooCommerce > Accounts & Privacy. That setting prevents guests from completing a purchase but does not replace or disable the Add to Cart button. A guest can still add products to their cart. This plugin catches the action earlier, at the product page itself.
Will it work on variable products?
Yes. The plugin hooks into WooCommerce's standard button output and add-to-cart validation, which cover simple, variable, and grouped product types.
What happens if a guest tries to add a product via a direct URL?
The woocommerce_add_to_cart_validation hook fires on all add-to-cart requests, including those triggered by URL parameters such as ?add-to-cart=123. The request is rejected and the guest sees an error notice.
Can I allow certain products to skip the restriction?
Not with this build. For per-product control, open Steem and add to the prompt that each product edit screen should have a checkbox to opt that product out of the guest restriction.
Does it redirect guests back to the product after they log in?
No. After logging in, guests land on the standard WooCommerce account page. Adding a return redirect to the product they came from requires a second small build.

The prompt

Loads into the composer so you can edit it first. Nothing is built, and nothing is charged, until you send it.

Build a WordPress plugin for WooCommerce that prevents guests from adding products to the cart. Add a settings page under WooCommerce > Settings > Guest Restrictions with two fields: an enable or disable toggle and a custom message field with the default text 'Please create an account or log in to add products to your cart'. On all WooCommerce product pages, when the current visitor is not logged in, replace the Add to Cart button with a styled div containing the custom message and two inline links labeled 'Log in' and 'Create account' that point to the WooCommerce login and registration page URLs. Also hook into woocommerce_add_to_cart_validation to reject any guest add-to-cart requests that arrive through other means such as quick-add buttons or direct URL parameters, calling wc_add_notice with an error and returning false. Show nothing extra to logged-in customers.

Build this pluginAbout 55 credits · the free plan includes enough for one

Read next

Other plugins you can build this way

Each loads into the composer, ready to edit.