Standard quantity quick add modal

Standard quantity quick add modal

martijn18
Excursionist
29 1 0

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
16115 2409 3122

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.
Get pass your Store Core Web Vital Free Speed Optimization Audit, Chat on WhatsApp | Skype : oscprofessionals-87 | Email: pallavi@oscprofessionals.com | Hire us | Guaranteed Site Speed Optimization | Website Free Audit | Shopify Theme Customization | Build Shopify Private App | Shopify SEO | Digital Marketing | Oscp Upsell & Cross sell App : Free | Oscp Sales & Volume Discount App : Free | Custom Pricing Wholesale App : Free
martijn18
Excursionist
29 1 0

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