Include WooCommerce product to all child categories

(1) Paste below code to your functions.php file

function my_enqueue() {
    wp_enqueue_script( 'my_custom_script', get_template_directory_uri() . '/js/myscript.js' );
}
add_action( 'admin_enqueue_scripts', 'my_enqueue' );

(2) Create myscript.js file and paste below code in it and place the file in ‘yourtheme/js/’ folder.

jQuery(document).ready(function () {

    jQuery('#categorychecklist').prepend('<input type="checkbox" id="selectall"><label for="selectall">Select all subcategories.</label><hr>');

    jQuery('#categorychecklist [type="checkbox"]:not(#selectall)').on('change', function () {
        if(jQuery('#selectall').is(':checked')) {
            jQuery(this).parent().parent().find('ul.children [type="checkbox"]').prop('checked', true);
        } else {
            jQuery(this).parent().parent().find('ul.children [type="checkbox"]').removeAttr('checked');
        }
    });
});

(3) Done – now selecting your parent category will automatically select child categories if Select all subcategories checkbox is selected on product edit page.