This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Child terms unticked by default

#38497
theapetheape
Participant

For anyone else who runs into this issue, here’s the complete code with the refresh issue solved too.

add_action('wp_footer', 'asp_add_menu_stop_checkbox_parent_child');
function asp_add_menu_stop_checkbox_parent_child() {
  ?>
<script>
jQuery(document).ready(function($){
	$(window).load(function(){
		$('*[data-lvl]').removeAttr('data-lvl');
		$(".asp_option_cat_level-1").hide();
		$(".asp_option_cat_level-2").hide();
		$(".asp_option_cat_level-0").click(function(){
			var $next = $(this).next(), checked = $(this).find('input[type=checkbox]').prop('checked');
			while ( $next.hasClass('asp_option_cat_level-1') || $next.hasClass('asp_option_cat_level-2') ) {
				if ( $next.hasClass('asp_option_cat_level-1') ) {
					$next.toggle();
				} else {
					$next.hide();
				}
				if ( !checked ) {
					$next.find('input[type=checkbox]').prop('checked', false);
				}
				$next = $next.next();
			}
		});
		$(".asp_option_cat_level-1").click(function(){
			var $next = $(this).next(), checked = $(this).find('input[type=checkbox]').prop('checked');
			while ( $next.hasClass('asp_option_cat_level-2') ) {
				$next.toggle();
				if ( !checked ) {
					$next.find('input[type=checkbox]').prop('checked', false);
				}
				$next = $next.next();
			}
		}); 
	});  
});
</script>
  <?php
}