0

I am trying to display all child categories from the parent categorie. This is my code so far:

function woocommerce_display_categories($atts, $content = null) {
  $prod_categories = get_terms( 'product_cat', array(
    'orderby'       => 'name',
    'order'         => 'DESC',
    'hide_empty'    => 0,
    'number'        => 3,
    'parent'        => 0,
)); 
foreach( $prod_categories as $prod_cat ) {
    $cat_thumb_id = get_woocommerce_term_meta( $prod_cat->term_id, 'thumbnail_id', true );
    $shop_catalog_img = wp_get_attachment_image_src( $cat_thumb_id, 'shop_catalog' );
    $term_link = get_term_link( $prod_cat, 'product_cat' );
    $categorie_child = get_term_children( $prod_cat->parent, 'product_cat' );
  {
  ?>
    <div class="col-md-4">
      <div class="entry">
        <div class="image-block mb-2">
          <a href="<?php echo $term_link; ?>">
            <img src="<?php echo $shop_catalog_img[0]; ?>" alt="<?php echo $prod_cat->name; ?>" class="img-fluid entry-image mx-auto" />
          </a>
        </div>
        <div class="entry-crumbs">
          <?php echo $categorie_child; ?>
        </div>
        <div class="entry-content pb-5">
          <h3 class="font-weight-bold"><?php echo $prod_cat->name; ?></h3>
          <p><?php echo $prod_cat->description; ?></p>
        </div>
        <div class="entry-link pt-5">
          <a href="<?php echo $term_link; ?>" class="btn-link">CHECK MODELS <span class="lnr lnr-arrow-right float-right"></span></a>
        </div>
      </div>
    </div>

<?php
  }
}
wp_reset_query(); 
}
add_shortcode( 'display_categories', 'woocommerce_display_categories' );

I have tried many solutions, but cannot seem to get it to work. $categorie_child keeps returning Array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.