2017-08-26 89 views
-1

請問您可以告訴我這段代碼有什麼問題嗎?我可以查看類別,但子類別是作爲類別的名稱。woocommerce子類別顯示不正確

$orderby  = 'name'; 
$empty  = 0; 

$args = array(
    'orderby'  => $orderby, 
    'show_count' => $show_count, 
    'hide_empty' => $empty, 
); 
$all_categories = get_terms('product_cat', $args); 

$html = ''; 
if (count($all_categories)) 
{ 
    $array = $all_categories; 
    foreach($all_categories as $category) 
    { 
     if($category->parent == 0) 
     { 
      $html .= '<div class="checkbox"><label><input type="checkbox" class="product-cageories" value="'.$category->term_id.'"> '.$category->name.'</label></div>'; 
      $j = 0; 
      foreach($array as $index => $child) 
      { 
       if($child->parent == $category->term_id) 
       {       
        $html .= '<div class="checkbox"><span class="pull-left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><label><input type="checkbox" class="product-cageories" value="'.$category->term_id.'"> '.$category->name.'</label></div>'; 
        unset($array[$index]); 
       } 

       if($child->term_id == $category->term_id) 
       { 
        unset($array[$index]); 
       } 
      } 
     } 
     else 
     { 
      continue; 
     } 
    } 
} 
echo $html; 
wp_die(); 

我已銷售圖片中的問題。 預先感謝您

more described in the picture

+0

到目前爲止您嘗試過什麼?堆棧溢出不是一個調試服務,問題「這個代碼有什麼問題」是脫離主題。預計您會在發佈之前***研究過您的問題,並嘗試親自編寫代碼***。如果遇到某些特定問題,請包括您嘗試過的內容以及[最小,完整和可驗證示例]的摘要(https://stackoverflow.com/help/mcve)。請閱讀[如何提問](https://stackoverflow.com/help/how-to-ask)。 – FluffyKitten

回答

0

下面是解 在的地方,你已經印刷種類的子類。

$orderby = 'name'; 
$empty = 0; 
$args = array('orderby' => $orderby, 'show_count' => $show_count, 
     'hide_empty' => $empty,); 
$all_categories = get_terms('product_cat', $args); 
$html = ''; 
if (count($all_categories)) { 
$array = $all_categories; 
foreach($all_categories as $category) { 
if($category->parent == 0) { 
$html .= '<div class="checkbox"><label><input type="checkbox" class="product-cageories" value="'.$category->term_id.'"> '.$category->name.'</label></div>'; 
$j = 0; 
foreach($array as $index => $child) { 
if($child->parent == $category->term_id) { 
$html .= '<div class="checkbox"><span class="pull-left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><label><input type="checkbox" class="product-cageories" value="'.$child->term_id.'"> '.$child->name.'</label></div>'; 
unset($array[$index]); 
} 
if($child->term_id == $category->term_id) { 
unset($array[$index]); 
} 
} 
}else{ 
continue; 
} 
} 
} 
echo $html; 
wp_die();