Magento2 Product detail page add checkbox before add to cart button
-
10-10-2020 - |
Question
In a Product Detail Page after Quantity add checkbox when checkbox button is checked than "add to cart" button stay active if not click on checkbox than disable button.
Thanks,
Solution
I have override the in custom theme file addtocart.phtml file after qty box i have added a checkbox. like
<input type="checkbox" name="add_to_cart" id="add_to_cart">
after that at the end of the page i have add custom jquery for check box is checked or not..! like
<script type="text/javascript">
require(['jquery'], function ($) {
jQuery(".tocart").click(function(){
if (jQuery('.control #add_to_cart').is(':checked') === false) {
alert("Please check at least one item");
return false;
}
});
});
</script>
and it's work..! try it.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange