I'm new in making modules, considering below code wondering how would be possible to verify if the checkbox has been selected:
my observer.php:
public function execute(\Magento\Framework\Event\Observer $observer) {
$item=$observer->getEvent()->getData('quote_item');
$product=$observer->getEvent()->getData('product');
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
if (???) {
// do this if checbox is selected
} else {
// do this if not selected
}
}
my viewfile.phtml
<?php
/** @var $block \Magento\Catalog\Block\Product\View */
?>
<?php $_product = $block->getProduct(); ?>
<?php if ($_product->isSaleable()):?>
<div id="rent>
<input id="my_checkbox" type="checkbox" name="vehicle" value="Rent">I want to rent this product
</div>
<script type="text/javascript">
require([
'jquery'
], function ($) {
$(document).ready(function () {
if($('#my_checkbox').prop('checked')) {
//checkbox is checked
} else {
//checkbox is NOT checked
}
});
}
});
</script>
<?php endif; ?>