Jump to content

Vanniek71

Circle Member
  • Posts

    3
  • Joined

  • Last visited

Everything posted by Vanniek71

  1. Yes I understand that part, it would be neat however if you could limit them to only adding say max qty 5 of one certain item to the cart when they are in the product page via the add to cart button. That would at least limit it somewhat!
  2. I just figured it out for those still wondering! (This may not be the exact way enjoysnacks808 did it in his site, but this just worked on mine) You need to go to Website Tools>Code Injection> Footer and then paste the code snippet like this: <script> document.addEventListener('DOMContentLoaded', (event) => { // data-item-id ="Enter your data item ID number here" // If someone enters more than 5, the value will revert to 5. // Be sure to add instructions for the qty limit in the product description. const quantityInput = document.querySelector('.product-quantity-input[data-item-id="Enter your data item ID number here"] input[type="number"]'); quantityInput.addEventListener('input', () => { if (quantityInput.value > 5) { quantityInput.value = 5; } }); }); </script> For the data item ID you would enter it like this const quantityInput = document.querySelector('.product-quantity-input[data-item-id="6669115df767f5244f9d1f8d"] input[type="number"]'); where your items actual data-item-id is in " ". Then you would need to update the numbers in the "if" statement to the max quantity you want to be able to be selected. Also make sure you have script tags <script> </script> around the code - that's what was breaking it for me. I was just pasting what enjoysnacks808 had posted and it did not work. I added the script tags and it started working. The only issue I see with this is that yes it allows a max quantity of X (Whatever you set) to be added to the cart at a time, but I can add that max quantity over and over again. e.g. the code above allows for a max qty of 5, I can add 5 and then once the item is added to my cart I can then click add to cart again and it will add 5 more. I don't think there is a way to limit the amount of times an item can be added to a cart like that (at least that I have found) so while this is a step int he right direction, still not the answer to those of us that need a quantity limit enforced.
  3. So I've added this to a code block in my products page, updated the data-item-id and I get nothing. The text that is highlighted in green in the above snippet is red in my code block so not sure if that matters. When I put the code in I am doing it in an HTML (Since I researched and found out selecting Javascript for the block is for displaying the code and not running it) block and pasting the following: <script> document.addEventListener('DOMContentLoaded', (event) => { // data-item-id ="667b74bca548e337af44eff8" // If someone enters more than 5, the value will revert to 5. // Be sure to add instructions for the qty limit in the product description. const quantityInput = document.querySelector('.product-quantity-input[data-item-id="667b74bca548e337af44eff8"] input[type="number"]'); quantityInput.addEventListener('input', () => { if (quantityInput.value > 5) { quantityInput.value = 5; } }); }); </script> I have also tried adding this to the Code Injection area of my site and still get nothing. I am allowed to enter whatever quantity I want to the cart. @enjoysnacks808 any ideas? About ready to put my head through my monitor lol
×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.