Title: checkbox group limit
Last modified: November 8, 2020

---

# checkbox group limit

 *  Resolved [mbadmin11](https://wordpress.org/support/users/mbadmin11/)
 * (@mbadmin11)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/checkbox-group-limit/)
 * Hey there!
    I was wondering if thre is a way to limit the checkbox group to a
   certain numer of choices. For example I’d like my users to choose at least 3 
   options on the checkbox group list… is it possible?
 * Thank you for your amazing work!

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [ThemeHigh](https://wordpress.org/support/users/themehigh/)
 * (@themehigh)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/checkbox-group-limit/#post-13643526)
 * 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!
 *  Thread Starter [mbadmin11](https://wordpress.org/support/users/mbadmin11/)
 * (@mbadmin11)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/checkbox-group-limit/#post-13643690)
 * 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!
 *  Plugin Author [ThemeHigh](https://wordpress.org/support/users/themehigh/)
 * (@themehigh)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/checkbox-group-limit/#post-13652281)
 * 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!
 *  Thread Starter [mbadmin11](https://wordpress.org/support/users/mbadmin11/)
 * (@mbadmin11)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/checkbox-group-limit/#post-13665772)
 * I tried adding the code (while leaving the previous one) but nothing happens…
   am I doing something wrong?
 * Thank you very much!
 *  Plugin Author [ThemeHigh](https://wordpress.org/support/users/themehigh/)
 * (@themehigh)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/checkbox-group-limit/#post-13666337)
 * Could you please raise a ticket through our website? We hope our technical team
   will be able to help you.
 * Thank you!
 *  Plugin Author [ThemeHigh](https://wordpress.org/support/users/themehigh/)
 * (@themehigh)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/checkbox-group-limit/#post-13706603)
 * We believe that your issue is resolved.
 * We are going to mark this thread as resolved.
 * Thank you!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘checkbox group limit’ is closed to new replies.

 * ![](https://ps.w.org/woo-extra-product-options/assets/icon-256x256.gif?rev=3241643)
 * [Extra Product Options For WooCommerce | Custom Product Addons and Fields](https://wordpress.org/plugins/woo-extra-product-options/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woo-extra-product-options/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woo-extra-product-options/)
 * [Active Topics](https://wordpress.org/support/plugin/woo-extra-product-options/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woo-extra-product-options/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woo-extra-product-options/reviews/)

## Tags

 * [checkbox group](https://wordpress.org/support/topic-tag/checkbox-group/)

 * 6 replies
 * 2 participants
 * Last reply from: [ThemeHigh](https://wordpress.org/support/users/themehigh/)
 * Last activity: [5 years, 5 months ago](https://wordpress.org/support/topic/checkbox-group-limit/#post-13706603)
 * Status: resolved