PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Displaying WooCommerce Child Categories

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Is there a way from the category dropdown to display the child categories in a nested view?

For example I have a parent category called:

Grinders (parent)

-Grinder Accessories (child)

- Grinder Documents (child)

But by default they're all displayed on the same level.

Any ideas?

Hello

Please drop me exact   link to the issue

https://cuttermasters.x10.mx/shop/

Under the search by Product Category, I want to see the category tree, so the parents first, and then the children under the parents in the dropdown.

 

 

 

Hello

Try  in  file  - \wp-content\plugins\woocommerce-products-filter\views\html_types\select.php - change  this code - https://share.pluginus.net/image/i20240808122235.png - to this - https://share.pluginus.net/image/i20240808122315.png

wp_kses_post(str_repeat('   ', $level))

and do a test

The image you sent is blank, so I can't see what you want me to change, but here is that file:

 

<?php if (!defined('ABSPATH')) die('No direct access allowed'); ?>
<?php
$collector = array();
WOOF_REQUEST::set('additional_taxes', $additional_taxes);
WOOF_REQUEST::set('hide_terms_count_txt', isset($this->settings['hide_terms_count_txt']) ? $this->settings['hide_terms_count_txt'] : 0);
$woof_hide_dynamic_empty_pos = (intval(WOOF_VERSION) === 1) ? 0 : get_option('woof_hide_dynamic_empty_pos');
//***
if (WOOF_REQUEST::isset('hide_terms_count_txt_short') AND intval(WOOF_REQUEST::get('hide_terms_count_txt_short')) !== -1) {
    if (intval(WOOF_REQUEST::get('hide_terms_count_txt_short')) === 1) {
        WOOF_REQUEST::set('hide_terms_count_txt', 1);
    } else {
        WOOF_REQUEST::set('hide_terms_count_txt', 0);
    }
}
//***
if (!function_exists('woof_draw_select_childs')) {
    function woof_draw_select_childs(&$collector, $taxonomy_info, $term_id, $tax_slug, $childs, $level, $show_count, $show_count_dynamic, $hide_dynamic_empty_pos) {
        $do_not_show_childs = (int) apply_filters('woof_terms_where_hidden_childs', $term_id);
        if ($do_not_show_childs == 1) {
            return"";
        }
        //***
        $request = woof()->get_request_data();
        $woof_hide_dynamic_empty_pos = (intval(WOOF_VERSION) === 1) ? 0 : get_option('woof_hide_dynamic_empty_pos');
        //***
        $current_request = array();
        if (woof()->is_isset_in_request_data(woof()->check_slug($tax_slug))) {
            $current_request = $request[woof()->check_slug($tax_slug)];
            $current_request = explode(',', urldecode($current_request));
        }
        //excluding hidden terms
        $hidden_terms = array();
        if (!WOOF_REQUEST::isset('woof_shortcode_excluded_terms')) {
            if (isset(woof()->settings['excluded_terms'][$tax_slug])) {
                $hidden_terms = explode(',', woof()->settings['excluded_terms'][$tax_slug]);
            }
        } else {
            $hidden_terms = explode(',', WOOF_REQUEST::get('woof_shortcode_excluded_terms'));
        }
        $childs = apply_filters('woof_sort_terms_before_out', $childs, 'select');
        ?>
        <?php if (!empty($childs)): ?>
            <?php foreach ($childs as $term) : ?>
                <?php
                $count_string ="";
                $count = 0;
                if (!in_array($term['slug'], $current_request)) {
                    if ($show_count) {
                        if ($show_count_dynamic) {
                            $count = woof()->dynamic_count($term, 'single', WOOF_REQUEST::get('additional_taxes'));
                        } else {
                            $count = $term['count'];
                        }
                        $count_format = apply_filters('woof_term_count_format', '(%d)',  $tax_slug);
$count_string = sprintf($count_format, $count);
                    }
                    //+++
                    if ($hide_dynamic_empty_pos AND $count == 0) {
                        continue;
                    }
                }
                if (WOOF_REQUEST::get('hide_terms_count_txt')) {
                    $count_string ="";
                }
                //excluding hidden terms
                $inreverse = true;
                if (isset(woof()->settings['excluded_terms_reverse'][$tax_slug]) AND woof()->settings['excluded_terms_reverse'][$tax_slug]) {
                    $inreverse = !$inreverse;
                }
                if (in_array($term['term_id'], $hidden_terms) == $inreverse) {
                    continue;
                }
                ?>
                <option <?php if ($show_count AND $count == 0 AND!in_array($term['slug'], $current_request)): ?>disabled=""<?php endif; ?> value="<?php echo esc_attr($term['slug']) ?>" <?php selected(in_array($term['slug'], $current_request)) ?> class="woof-padding-<?php echo esc_attr($level) ?>"><?php echo esc_html(str_repeat(' ', $level)) ?><?php
                    if (has_filter('woof_before_term_name'))
                       echo wp_kses_post(wp_unslash(apply_filters('woof_before_term_name', $term, $taxonomy_info)));
                    else
                        echo esc_html($term['name']);
                    ?> <?php echo wp_kses_post(wp_unslash($count_string)) ?></option>
                <?php
                if (!isset($collector[$tax_slug])) {
                    $collector[$tax_slug] = array();
                }
                $collector[$tax_slug][] = array('name' => $term['name'], 'slug' => $term['slug'], 'term_id' => $term['term_id']);
                //+++
                if (!empty($term['childs'])) {
                    woof_draw_select_childs($collector, $taxonomy_info, $term['term_id'], $tax_slug, $term['childs'], $level + 1, $show_count, $show_count_dynamic, $hide_dynamic_empty_pos);
                }
                ?>
            <?php endforeach; ?>
        <?php endif; ?>
        <?php
    }
}
$select_id ="woof_tax_select_" . $tax_slug;
?>
<label class="woof_wcga_label_hide"  for="<?php echo esc_attr($select_id) ?>"><?php echo esc_html(WOOF_HELPER::wpml_translate($taxonomy_info)); ?></label>
<select id='<?php echo esc_attr($select_id) ?>' class="woof_select woof_select_<?php echo esc_attr($tax_slug) ?>" name="<?php echo esc_attr($this->check_slug($tax_slug)) ?>">
    <option value="0"><?php echo esc_html(WOOF_HELPER::wpml_translate($taxonomy_info)) ?></option>
    <?php
    $woof_tax_values = array();
    $current_request = array();
    $request = $this->get_request_data();
    if ($this->is_isset_in_request_data($this->check_slug($tax_slug))) {
        $current_request = $request[$this->check_slug($tax_slug)];
        $current_request = explode(',', urldecode($current_request));
    }
//excluding hidden terms
    $hidden_terms = array();
    if (!WOOF_REQUEST::isset('woof_shortcode_excluded_terms')) {
        if (isset(woof()->settings['excluded_terms'][$tax_slug])) {
            $hidden_terms = explode(',', woof()->settings['excluded_terms'][$tax_slug]);
        }
    } else {
        $hidden_terms = explode(',', WOOF_REQUEST::get('woof_shortcode_excluded_terms'));
    }
    $terms = apply_filters('woof_sort_terms_before_out', $terms, 'select');
    $shown_options_tags = 0;
    ?>
    <?php if (!empty($terms)): ?>
        <?php foreach ($terms as $term) : ?>
            <?php
            $count_string ="";
            $count = 0;
            if (!in_array($term['slug'], $current_request)) {
                if ($show_count) {
                    if ($show_count_dynamic) {
                        $count = $this->dynamic_count($term, 'single', WOOF_REQUEST::get('additional_taxes'));
                    } else {
                        $count = $term['count'];
                    }
                    $count_format = apply_filters('woof_term_count_format', '(%d)',  $tax_slug);
                    $count_string = sprintf($count_format, $count);
                }
                //+++
                if ($hide_dynamic_empty_pos AND $count == 0) {
                    continue;
                }
            }
            if (WOOF_REQUEST::get('hide_terms_count_txt')) {
                $count_string ="";
            }
            //excluding hidden terms
            $inreverse = true;
            if (isset(woof()->settings['excluded_terms_reverse'][$tax_slug]) AND woof()->settings['excluded_terms_reverse'][$tax_slug]) {
                $inreverse = !$inreverse;
            }
            if (in_array($term['term_id'], $hidden_terms) == $inreverse) {
                continue;
            }
            ?>
            <option <?php if ($show_count AND $count == 0 AND!in_array($term['slug'], $current_request)): ?>disabled=""<?php endif; ?> value="<?php echo esc_attr($term['slug']) ?>" <?php selected(in_array($term['slug'], $current_request)) ?>><?php
                if (has_filter('woof_before_term_name'))
                    echo wp_kses_post(wp_unslash(apply_filters('woof_before_term_name', $term, $taxonomy_info)));
                else
                    echo esc_html($term['name']);
                ?> <?php echo wp_kses_post(wp_unslash($count_string)) ?></option>
            <?php
            if (!isset($collector[$tax_slug])) {
                $collector[$tax_slug] = array();
            }
            $collector[$tax_slug][] = array('name' => $term['name'], 'slug' => $term['slug'], 'term_id' => $term['term_id']);
            //+++
            if (!empty($term['childs'])) {
                woof_draw_select_childs($collector, $taxonomy_info, $term['term_id'], $tax_slug, $term['childs'], 1, $show_count, $show_count_dynamic, $hide_dynamic_empty_pos);
            }
            $shown_options_tags++;
            ?>
        <?php endforeach; ?>
    <?php endif; ?>
</select>
<?php if ($shown_options_tags == 0): ?>
    <input type="hidden" class="woof_hide_empty_container" value=".woof_container_<?php echo esc_attr($tax_slug) ?>">
<?php endif; ?>
<?php
//this is for woof_products_top_panel
if (!empty($collector)) {
    foreach ($collector as $ts => $values) {
        if (!empty($values)) {
            foreach ($values as $value) {
                ?>
                <input type="hidden" value="<?php echo esc_html($value['name']) ?>" data-anchor="woof_n_<?php echo esc_attr($this->check_slug($ts)) ?>_<?php echo esc_attr($value['slug']) ?>" />
                <?php
            }
        }
    }
}
//we need it only here, and keep it in WOOF_REQUEST for using in function for child items
WOOF_REQUEST::del('additional_taxes');

Hello

Please check these link:

from - https://share.pluginus.net/image/i20240808122235.png - to - https://share.pluginus.net/image/i20240808122315.png