1

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.

Customizable Options

asked Mar 26, 2021 at 6:29

1 Answer 1

2

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>
answered Mar 26, 2021 at 8:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.