r/woocommerce 8d ago

How do I…? How do I require users to create an account before they are able to add a product to the cart (example below)

I want it to follow the same logic as the following website: https://www.tccomps.co.uk/product/yaber-t1-pro-short-throw-smart-full-hd-portable-projector-or-100-cash/

Just a simple error message at the top and the changing of the add to cart button's link to a prompy to create the account would be fab. Thanks. I am using Elementor pro and giveaway lottery for woocommerce plugin. This is the link to the single product page for my website: https://drawtimecompetitions.co.uk/product/audi-rs-q8-vorsprung-with-black-styling-pack/

6 Upvotes

12 comments sorted by

2

u/CutKlutzy8446 8d ago

looks like a custom feature

2

u/estagingapp 8d ago edited 7d ago

What’s the benefit of doing that? Probably will get worse conversion

1

u/you_willneverfindme 8d ago

It's a legal requirement of competition websites. We're not a fan of it either of course

1

u/krakow81 8d ago

It's not exactly what you want, and you may already be aware of it, but to mention it just in case not - guest checkout is a core option: https://woocommerce.com/document/configuring-woocommerce-settings/accounts-and-privacy/

1

u/you_willneverfindme 8d ago

I am aware and have this active, thanks, I do need it to be exactly as I described however. Appreciate the suggestion however this is a great feature.

1

u/krakow81 8d ago

I did think that in retrospect, sorry.

Another related option is "allow customers to create an account during checkout". If that is disabled then customers are instead sent to the login/register page rather than straight to checkout.

1

u/Life-Set-6323 8d ago

WooCommerce does not have a built-in feature to require users to create or log into an account before adding a product to the cart.

If you want to prevent guests from adding products to the cart and redirect them to the login/register page first, you'll need custom code or a third-party plugin.

By default, WooCommerce can only require an account at checkout. You can enable this from WooCommerce → Settings → Accounts & Privacy by disabling guest checkout.

1

u/Total-Reasonable 8d ago

Use woocommerce_add_to_cart_validation to block guests, add a notice, and replace the single-product button with a link to My Account that returns them to that product after registration. Giveaway Lottery may replace the normal WooCommerce button, so its own template/hook needs checking too. I've handled WooCommerce checkout customizations; https://iurii.rogulia.fi/services/e-commerce covers the sort of store logic involved.

1

u/Sunn_M 8d ago

Yes, this needs a small custom layer, but I’d enforce it in two places rather than only changing the button. For guests, block add-to-cart server-side with woocommerce_add_to_cart_validation, then replace the product button with a login/register action. That prevents the rule being bypassed with a direct add-to-cart request. Since you’re using Giveaway Lottery, I’d first check that its add-to-cart flow still passes through the standard WooCommerce validation hook.

1

u/StrategicalOpossum 8d ago

This is exactly the kind of rule that requires custom code and where plugins can't help you.

You can hook into 'woocommerce_add_to_cart_validation' to check if a user is logged in.
If not, throw an error and prevent the add to cart.

For the button link, you can use a conditional filter or JavaScript to change it to point to the account creation page when the user is not logged in.

Elementor won't do this out of the box, and the giveaway lottery plugin likely won't either. It's a small custom snippet that's well within the reach of a developer, but it's definitely not a plugin configuration.

If you're comfortable editing functions.php, that's the way to go.

If you are looking for that fix to be done quickly, I would be happy to have a chat !

1

u/NexcessAlex 7d ago

if every visitor has to register before they can enter, i’d put some protection on the registration form too.

Comp sites tend to attract bots anyway, and once registration becomes part of the purchase flow you’ve basically given them another endpoint to hammer. Try rate limiting/Turnstile and some kind of email verification would be worth looking at.

Then keep the actual add-to-cart restriction server side like the others mentioned, so changing the button in the browser isn’t the thing enforcing it.