Rebuy does not currently have an integration with any 3rd party apps that restrict product quantity. Apps that perform this function (ex: MinMaxify) often cause code conflicts when used in conjunction with Rebuy.
Additionally at this time there are not native settings within Smart Cart that allow for product quantity restrictions.
However there are methods we can use to restrict product quantity in Smart Cart, we'll discuss these options in detail below.
How to hide quantity buttons in Smart Cart
Your theme may already restrict users from adding too many of a product to the cart, in that case we need to ensure they cannot increase the quantity within Smart Cart.
Example: A product that your theme limits to one per order.
You can tag that product with smart-cart-hide-qty
. This tag will automatically hide the quantity buttons on that product in Smart Cart.
How to set a maximum quantity on products in Smart Cart
The instructions below include the use of code. The code is pre-built for you. You need only copy and paste the code and make very minor adjustments to suit your needs. Detailed instructions of what adjustments to make are included.
Please note this is a proposed work around to allow for a behavior that is not natively supported at this time. Therefore we cannot guarantee it will work for all merchants in all situations.
We advise first testing this in a duplicate Smart Cart using preview mode, to see if this approach suits your needs.
Perhaps you need to restrict users to no more than 5 of a single product (or a number that suits you). We can achieve this by adding code to the Smart Cart.
But which products are quantity restricted? Is it all products or only some products?
We'll cover both scenarios below.
All products carry quantity restrictions
You can add the below code to the Smart Cart > Advanced > Ready section.
You only need to adjust the maximum quantity number.
<-- Click here to see instructions.
<-- Click here to see instructions.
/* limit quantity for ALL products in Smart Cart */
function limitItemQuantities() {
setTimeout(() => {
/* pull in all the cart items */
const cartItems = Rebuy.SmartCart.items();
/* check quantity and lower if needed */
cartItems.forEach(item => {
if (item.quantity > 5) { /* <-- this is the max quantity a user can add */
/* lower item quantity back to the maximum */
Rebuy.Cart.setItemQuantity(item, 5) /* <-- this is the max quantity a user can add */
}
})
}, 400);
}
document.addEventListener('rebuy:cart.change', limitItemQuantities)
This code is preset to limit all products to 5. If a user raises the quantity to 6, that product will automatically be lowered back to 5. They can decrease but cannot increase above the limit set.
The lines below show you exactly where you need to edit the code above.
if (item.quantity > 5) {/*<-- this is the max quantity a user can add */
Rebuy.Cart.setItemQuantity(item, 5) /* <-- this is the max quantity a user can add */
Change the 5 in both places to the number you need. Both numbers should match.
Only some products have quantity restrictions
You can add the below code to the Smart Cart > Advanced > Ready section.
You'll need to
Adjust the maximum quantity number.
Add a tag to the products that are quantity restricted.
Add that same tag to the code below.
<--Click here to see instructions.
<--Click here to see instructions.
/* limit quantity for tagged products in Smart Cart */
function limitItemQuantities() {
setTimeout(() => {
/* pull in all the cart items */
const cartItems = Rebuy.SmartCart.items();
/* check for product tag and quantity, lower quantity if needed */
cartItems.forEach(item => {
if (item.product?.tags.includes("Place tag here") && item.quantity > 5) { /* <-- this is the max quantity for tagged products */
/* lower item quantity back to the maximum */
Rebuy.Cart.setItemQuantity(item, 5) /* <-- this is the max quantity for tagged products */
}
})
}, 300);
}
document.addEventListener('rebuy:cart.change', limitItemQuantities)
This code is preset to limit products with a certain tag to 5. If a user raises the quantity to 6, that product will automatically be lowered back to 5. They can decrease but cannot increase above the limit set.
The lines below show you exactly where you need to edit the code above.
Tag your products that have quantity restrictions, then add that same tag to the code, where is says 'Place tag here'. How Shopify tags work.
Example: If your products are tagged "max5" the code should read.
if (item.product?.tags.includes("max5") && item.quantity > 5) {
Keep the tag within the quotation marks.
if (item.product?.tags.includes("max5") && item.quantity > 5) { /* <-- this is the max quantity for tagged products */
Rebuy.Cart.setItemQuantity(item, 5) /* <-- this is the max quantity for tagged products */
Change the 5 in both places to the number you need. Both numbers should be the same.
Where to find the Smart Cart > Advanced > Ready section
Open the Smart Cart you're woking in or create a new Smart Cart if needed. Go into the advanced settings, and enable the "ready callback."
Scroll down to the advanced section (toggle it on if needed) and you'll see the Ready section below.
How the code will function once added
This products quantity cannot be increased higher than 5. They can decrease quantity but trying to increase it causes an automatic adjustment back to 5.
You can set the number limit you need, 5 is merely an example.
Suggestions for notifying customers of product quantity restrictions
If you're limiting quantity on products your theme should already make that clear to users. For example, displaying text on the PDP's of those products.
If needed you can use the Smart Cart Announcement Bar to display this information to users.
If you can configure your products to carry line item properties, Smart Cart will display them automatically.
You could use the Custom Code section of Smart Cart to add a new element. You can add a class name to this element to give it CSS styling and adjust the text as you'd like.
Finally, you might consider using a Smart Cart template to add text to Smart Cart elsewhere, notifying users of your product quantity restrictions.