Unfortunately, there is no direct option available in our plugin to achieve your requirement. However, you can achieve this using a custom javascript code.
Initially, you have to add th-limit-checkbox in the Wrapper Class inside checkbox groups field. Then add the below code snippet in your child theme’s functions.php file.
add_action('wp_footer', 'sa34er_limit_checkbox_group_selection', 9999);
function sa34er_limit_checkbox_group_selection(){
if(is_product()) {
?>
<script>
(function($, window, document) {
$('.th-limit-checkbox input[type="checkbox"]').on('change', function() {
if($('.th-limit-checkbox input[type="checkbox"]:checked').length > 3) { // Modify number
this.checked = false;
}
});
}(window.jQuery, window, document));
</script>
<?php
}
}
We hope this will help.
Thank you!
This is much appreciated! Your solution works perfectly as long as you select maximum 3 boxes, but you can still select just one or two.
Is there a way to make it work as exact number? So the user must select exaclty trhee options, no more and no less?
Thanks again!
Please add the below code in your child theme’s functions.php file.
add_action('wp_footer', 'fe36t_min_checkbox_group_selection', 9999);
function fe36t_min_checkbox_group_selection(){
if(is_product()) {
?>
<script>
(function($, window, document) {
$(document).on('submit','form.cart',function(e){
if($('.th-limit-checkbox input[type="checkbox"]:checked').length < 3) { // Modify number
alert("Please select atleast 3 options");
e.preventDefault();
}
});
}(window.jQuery, window, document));
</script>
<?php
}
}
This will show a javascript warning if the customer clicks the add to cart button by selecting options less than 3.
Please note that you have to keep the previous code snippet also in your child theme’s functions.php file.
We hope this will help.
Thank you!
I tried adding the code (while leaving the previous one) but nothing happens…am I doing something wrong?
Thank you very much!
Could you please raise a ticket through our website? We hope our technical team will be able to help you.
Thank you!
We believe that your issue is resolved.
We are going to mark this thread as resolved.
Thank you!