Standard quantity quick add modal

Standard quantity quick add modal

martijn18
Excursionist
42 1 3

To adjust the standard quantity I added the following code:

     <script>
   {% if product.type == 'Rood' %}
    document.addEventListener('DOMContentLoaded', function() {
      try {
        document.querySelector('input.quantity__input').value = 6;
        document.querySelector('button[name="minus"]').classList.remove('disabled');
      } catch {} 
    });
  {% endif %}
</script>

This code gives the customer a default quantity of 6 but allows them to increase/decrease it.
Currently, this only works on the product page itself. However, we also want to have this in the quick-add modal. Where do I have to insert this code and do I have to adjust it as well?
Store link is marwijn.com password is test123


Replies 2 (2)

oscprofessional
Shopify Partner
16366 2440 3188

Hello@martijn18 
Please Try This Javascript

<script>
document.addEventListener('DOMContentLoaded', function() {
  function setDefaultQuantity() {
    try {
      // Adjust selectors if needed for the quick-add modal
      const quantityInput = document.querySelector('input.quantity__input');
      const minusButton = document.querySelector('button[name="minus"]');
      
      if (quantityInput) {
        quantityInput.value = 6;
      }
      if (minusButton) {
        minusButton.classList.remove('disabled');
      }
    } catch (e) {
      console.error('Error setting default quantity:', e);
    }
  }

  // Set default quantity on the main product page
  {% if product.type == 'Rood' %}
    setDefaultQuantity();
  {% endif %}

  // Set default quantity when the quick-add modal is shown
  document.addEventListener('quickAddModalShown', function() {
    setDefaultQuantity();
  });
});
</script>

Summary

  1. Identify the correct elements in the quick-add modal.
  2. Adjust your JavaScript to handle these elements.
  3. Ensure the event for showing the quick-add modal is correctly managed to apply your script.
Hire us | Pass Core Web Vital | B2B Wholesale Experts | Claim Your Free Website Review |
Connect with Us: WhatsApp | Skype: oscprofessionals-87 | Email: pallavi@oscprofessionals.com |
Custom Shopify SolutionsPrivate Apps, Theme Customization & SEO | Digital Marketing |
OSCP Apps: Discount Suite | Wholesale App | Bundle & Upsell | Shipping Discount | and more...
martijn18
Excursionist
42 1 3

Should I paste it next to the original code in theme.liquid?