Site icon Hip-Hop Website Design and Development

Show an inventory subcategories underneath the primary product class thumbnails?

So I’ve been searching for days now to both discover a snippet of code or plugin on-line that any person else has created to do that in addition to making an attempt to switch items of code that do one thing comparable that I discovered whereas digging by way of the Woocommerce core recordsdata and may’t discover something that works.

What I’m making an attempt to do is take the prevailing “Product Categories” web page that shows every of the primary product classes with a thumbnail and class title and I wish to add an inventory of subcategories underneath every of the primary classes.

So what I’ve proper now’s a web page that simply shows my essential product classes like this:
https://imgur.com/a/Kxm4VhY

And what I’ve been making an attempt to create is a web page that appears like this:
https://imgur.com/a/hu9WLtb

At the moment the Product Classes are displayed inside the loop as checklist gadgets utilizing the template content-product_cat.php which appears to be like like this:

<?php
/**
 * The template for displaying product class thumbnails inside loops
 *
 * This template might be overridden by copying it to yourtheme/woocommerce/content-product_cat.php.
 *
 * HOWEVER, once in a while WooCommerce might want to replace template recordsdata and also you
 * (the theme developer) might want to copy the brand new recordsdata to your theme to
 * keep compatibility. We strive to do that as little as doable, however it does
 * occur. When this happens the model of the template file shall be bumped and
 * the readme will checklist any vital adjustments.
 *
 * @see     https://docs.woocommerce.com/doc/template-structure/
 * @package deal WooCommerce/Templates
 * @model 2.6.1
 */

if ( ! outlined( 'ABSPATH' ) ) {
    exit;
}
?>
<li <?php wc_product_cat_class( '', $class ); ?>>
    <?php
    /**
     * woocommerce_before_subcategory hook.
     *
     * @hooked woocommerce_template_loop_category_link_open - 10
     */
    do_action( 'woocommerce_before_subcategory', $class );

    /**
     * woocommerce_before_subcategory_title hook.
     *
     * @hooked woocommerce_subcategory_thumbnail - 10
     */
    do_action( 'woocommerce_before_subcategory_title', $class );

    /**
     * woocommerce_shop_loop_subcategory_title hook.
     *
     * @hooked woocommerce_template_loop_category_title - 10
     */
    do_action( 'woocommerce_shop_loop_subcategory_title', $class );

    /**
     * woocommerce_after_subcategory_title hook.
     */
    do_action( 'woocommerce_after_subcategory_title', $class );

// Start my edit to show Subcategories

    $classes = $category->kids;

    foreach ( $classes as $class ) {
        ?>
            <li class="wc-block-product-categories-list-item">
                <a href=" <?php esc_attr( get_term_link( $category->term_id, 'product_cat' ) ); ?>">
                    '<?php esc_html( $category->identify ); ?>'
                </a>
            </li>
            <?php
    }

// Finish my edit to show Subcategories

    /**
     * woocommerce_after_subcategory hook.
     *
     * @hooked woocommerce_template_loop_category_link_close - 10
     */
    do_action( 'woocommerce_after_subcategory', $class );
    ?>
</li>

I pulled and altered the code in between the edit strains from the file ProductCategories.php as this code is used to show the kid classes inside the full hierarchical class checklist that may be added as a block within the wordpress web page builder. It’s a part of the Woocommerce core recordsdata.

I’ve tried including an motion that calls a perform within the features.php file in addition to simply straight modifying the template as above and I can get it to show plain textual content within the house under every essential class however irrespective of which method I strive I can’t get it to show the kid classes.

Does anyone know what I’m doing fallacious or if I’m going about this the fallacious method or one thing?