I have added multiple Customizable Options(e.g. Extra Buffalo Cheese,Extra Aioli,Extra Hollandaise,Extra Caesar Dressing) for products as shown in the image below. I want to restrict this option selection to a maximum to 2 only. basically, the user can select any 2 values for extra not more than two.
Is there a way to achieve this with CMS or through code as I have no idea here ? or Any other better way to do achieve the same.
1 Answer 1
Copy and override default template in your custom theme app/design/frontend/Your/theme/Magento_Catalog/templates/product/composite/fieldset/options/view/checkable.phtml and add below code at end of file
<script type="text/javascript">
require(['jquery', 'jquery/ui'], function($){
$('input.product-custom-option').on('change', function(evt) {
if($('input.product-custom-option').parent().find('input.product-custom-option:checked').length >= 2) {
$('input.product-custom-option').parent().find('input.product-custom-option:not(:checked)').attr("disabled", true);
}else{
$('input.product-custom-option').parent().find('input.product-custom-option:not(:checked)').removeAttr("disabled");
}
});
});
</script>