Created
June 28, 2020 09:52
-
-
Save gvgvgvijayan/9f903dafddc85a19c980a776b000ae2e to your computer and use it in GitHub Desktop.
This gist is used in the tutorial https://www.vijayan.in/how-to-add-quantity-input-in-shop-page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('wp_footer', 'update_quantity_attribute'); | |
function update_quantity_attribute() | |
{ | |
?> | |
<script type='text/javascript'> | |
let simpleProductInput = document.querySelectorAll('.product-type-simple .quantity > input'); | |
simpleProductInput.forEach(dom => { | |
dom.addEventListener('input', e => { | |
e.target.parentElement.nextElementSibling.setAttribute('data-quantity', e.target.value); | |
}); | |
}); | |
</script> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment