Shopify themes, liquid, logos, and UX
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
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>
Should I paste it next to the original code in theme.liquid?
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024