저는 자동차 부품을 판매하는 Wordpress WooCommerce 사이트가 있습니다. 각 파트 (제품)에 대해 파트에 지정할 수있는 고유 한 제품 카테고리를 만들었습니다. 그래서 예. 헤드 라이트 (부품)는 3-Door 1999 Blue Alfa Romeo 156 1.1 가솔린 매뉴얼에서 얻을 수 있습니다.Wordpress WooCommerce는 개별 제품에 대해 중첩 된 제품 카테고리를 표시합니다.
개별 제품 페이지에서이 부품과 관련된 제품 범주 만 중첩 목록을 표시하려고합니다. 따라서 파트에 태그를 지정하면 아래 이미지와 같은 중첩 된 뷰가 표시됩니다.
그러나 두 번째 이미지 아래의 현재 코드에는이 부분을 포함하여 연결된 부품이있는 모든 제품 카테고리가 표시됩니다. 아래의 두 번째 이미지에서 볼 수 있듯이 나는 다른 자동차 제작자에게 할당 된 많은 부품을 보유하고 있으며이 부품을 위해 모두 표시됩니다. 나는이 부분이이 부분과 관련된 Product Categories를 표시하기를 원합니다. 따라서 Alfa Romeo 만 표시해야합니다.이 부분에 태그가 지정되었는지 여부에 관계없이 부품이 포함 된 다른 모든 제품 카테고리가 아닙니다.
아무도 도와 줄 수 있습니까?
현재 코드
<?php
$woocCategoryTerms = get_terms('product_cat', array(
'order' => 'ASC',
'hide_empty' => true, // (boolean)
'parent' => 0, // (integer) Get direct children of this term (only terms whose explicit parent is this value). If 0 is passed, only top-level terms are returned. Default is an empty string.
'hierarchical' => true, // (boolean) Whether to include terms that have non-empty descendants (even if 'hide_empty' is set to true).
));
foreach($woocCategoryTerms as $wooCategoryTerm) :
?>
<ul>
<li>
<a href="<?php echo get_term_link($wooCategoryTerm -> slug, $wooCategoryTerm -> taxonomy); ?>">
<?php
echo $wooCategoryTerm -> name;
?>
</a>
<ul class="wsubcategs">
<?php
$wooSubArgs = array(
'hierarchical' => true,
'hide_empty' => true,
'parent' => $wooCategoryTerm -> term_id,
'taxonomy' => 'product_cat'
);
$wooSubCategories = get_categories($wooSubArgs);
foreach ($wooSubCategories as $wooSubCategory):
?>
<li>
<a href="<?php echo get_term_link($wooSubCategory -> slug, $wooSubCategory -> taxonomy);?>">
<?php
echo $wooSubCategory -> name;
?>
</a>
</li>
<?php
endforeach;
?>
</ul>
</li>
</ul>
<?php
endforeach;
?>