Facebook
From Władysław, 5 Years ago, written in PHP.
Embed
Download Paste or View Raw
Hits: 245
  1. <?php
  2. $term = get_queried_object()->term_id;
  3. $termid = get_term($term, 'product_cat' );
  4. if($termid->parent > 0)
  5.     {
  6.         $args = array(
  7.             'orderby'       => 'name',
  8.             'order'         => 'ASC',
  9.             'hide_empty'    => false,
  10.             'child_of'      => $termid->parent,
  11.     );
  12.     $siblingproducts = get_terms( 'product_cat', $args);
  13.     foreach ($siblingproducts as $siblingproduct) {
  14.                 if ($siblingproduct->term_id == $term ) {
  15.                 echo '<li class="subcatmenu"><span class="subcatlinkmenu"><span class="fusion-megamenu-bullet"></span>';
  16.                 }
  17.                
  18.                 else {  
  19.                 echo '<li class="subcatmenu"><span class="subcatlinkmenu"><span class="fusion-megamenu-bullet"></span>';
  20.                 }  
  21.                 echo '<a href="';
  22.                 echo get_term_link( $siblingproduct );
  23.                 echo '">';
  24.                 echo $siblingproduct->name;
  25.                 echo '</a></span></li>';
  26.         }
  27.     }
  28.        
  29.         else {
  30.         $args = array(
  31.             'orderby'       => 'name',
  32.             'order'         => 'ASC',
  33.             'hide_empty'    => false,
  34.             'parent'            => $term
  35.         );
  36.     $subproducts = get_terms( 'product_cat', $args);
  37.     foreach ($subproducts as $subproduct) {
  38.         echo '<li class="subcatmenu"><span class="subcatlinkmenu"><span class="fusion-megamenu-bullet"></span><a href="'.get_term_link( $subproduct ).'">';
  39.         echo $subproduct->name;
  40.         echo '</a></span></li>';
  41. }
  42. }
  43.  
  44. ?>