Only allow one item in basket

Solved
lecker_bierchen
New Member
1 0 0

Hi. I plan a strange setup for selling virtual goods. With my current setup I am not able to split different product types in my order processing. I plan to do a MVP and do not want to spent to much resources in it.

 

Is there a way to only allow one item (but in higher quantities) in the basket. So I add 5 times item A. When I add item B I get an error message "Please finish the order for every item separate".

0 Likes
JoesIdeas
Shopify Expert
1188 104 288

This is an accepted solution.

Ya, the way I would approach it is with javascript + the Shopify ajax api.

1) Set an event listener on your add to cart button so that when someone clicks on it, before adding to cart it checks to see how many line items are in the cart.

2) If there are > 0 line items in the cart, check to see if the line item in the cart is the same as the product you're adding (so they can add more quantity any time).

3) If > 0 line items and the line item in cart does not match the one on the product page, then show an error message instead of adding the product to cart.

Here's the documentation: https://shopify.dev/docs/themes/ajax-api. You'll want to use GET cart.js specifically for this project: https://shopify.dev/docs/themes/ajax-api/reference/cart#get-cart-js

If you need help from a developer feel free to reach out to my team at speedboostr.com/contact. We do customizations like this all the time.

Founder of Speed Boostr (Shopify optimization experts, theme customization, custom app development).
Creator of Shopify Analyzer (first performance analysis tool for Shopify sites, free for the Shopify community).
Creator of Order Automator (auto tag orders and customers + auto fulfill orders + email notifications).
Creator of Theme Scientist (A/B testing app) and Tip Jar (add a tip button to your store).