How can I force customer to login before they add a product to cart?

22 0 0

Hello, due the the special nature of my site. I need customer to create an account or login before they put product to cart.

So I need to redirect customer to login page or registration page when they click "add to cart". And then automatically add back the product which they was clicking to add to the cart before login or registration.

Could anyone please share my some code to achieve that?I am new to coding but try to learn fastly now. Thanks so much

Shopify Staff
Shopify Staff
105 7 12

Hey @Newbiebie

I'm Finley from the Social Care team here at Shopify. Thanks for your question.

I understand that you'd like your customers to be redirected to the account login page when they add a product to the cart. After the account is created, you'd like the customer to be redirected back to the original product page. Is that right?

Though I don't have the specific code for this, you might be interested in one of these options:

1) The third-party app Locksmith offers you control over who can see what on your website.

For example, you could lock your entire shop, so a customer would have to log in to access your store. Alternatively, you could lock specific pages only.

I recommend giving the app a try to see if this works for you. Should you have any questions, the app's contact information in the Support section on the right-hand side of the app listing:



2) If you're happy for your customers to add all of their products to the cart first and only be required to log in or create an account once they're ready to checkout, then you can make use of the built-in Customer Accounts feature.

I recommend setting your preference as Accounts are required.

In this case, your customers would need to create an account, or be logged in through their previously created account to move forward to the checkout.

You can set your customer account preferences from your Shopify Admin > Settings > Checkout > Customer Accounts like so:



3) An option I also wanted to mention is hiring an expert from The Shopify Experts Directory. This is a good option if an app doesn't meet your specific needs and you'd like some customizations made on your website by an expert who has been vetted by Shopify.

Duplicating your theme

Last but not least, I wanted to mention that if you do end up making changes to your theme's code, it's best practice to first duplicate your theme.

From your Shopify Admin, you can navigate to your Online Store> Themes

From there, click Actions next to the theme and then Duplicate.

You'll see that a new file is created as a backup for you in case your code changes don't go exactly to plan.

I hope this helps! Feel free to reach out if there's anything I can clarify.


Finley | Social Care @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog