2016-08-13 5 views
0

브랜드, 색상, 크기 등과 같은 상위 카테고리로 구성된 제품이있는 Woocommerce 샵에서 일하고 있습니다.이 최상위 카테고리에는 각각 하위 카테고리 수 : 예 : 색상의 하위 카테고리에 빨간색, 파란색, 분홍색 등이 포함됩니다.부모를 기반으로하는 Woocommerce 제품에 특정 제품 하위 카테고리 제목 표시

클라이언트는 각 제품의 미리보기 아래에 각 제품의 브랜드 및 크기 (신발은 제품)를 표시하려고합니다. 전면 및 아카이브 페이지.

각 제품은 하나의 브랜드이지만 여러 크기를 사용할 수 있습니다.

그래서 본질적으로, 그래서 같이 하나의 제품 만 특정 하위 범주의 제목을 표시하는 방법이 있는지 알고 있어야합니다

[Product Thumbnail here] 
[Price info here] 
Brand: Nike 
Size(s): 8, 8.5, 9 

난 그냥 subcat 제목, 링크가 아닌 필요합니다. 나는 이것에 대한 해결책이 content-product.php에서 get_terms() 함수를 호출하는 것과 관련이있을 것이라고 생각하지만 제품의 특정 하위 범주 만 나열하는 방법을 파악하지 못했습니다.

If this product is in the Brand category, 
    Then show its subcategory. 

If this product is in the Size category, 
    Then show its subcategories. 
+0

뭔가를이 코드를 붙여 넣습니다 이렇게하면 http://awesomescreenshot.com/0ea6341ab9 –

답변

0

확인이 링크 :

내가 찾고있는 코드는 기본적으로 말할 것이다

https://developer.wordpress.org/reference/functions/get_terms/

과 상점 페이지에

global $product; 

// Get product attributes 
$attributes = $product->get_attributes(); 

if (! $attributes) { 
    echo "No attributes"; 
} 

foreach ($attributes as $attribute) { 

     echo $attribute['name'] . ": "; 
     $product_attributes = array(); 
     $product_attributes = explode('|',$attribute['value']); 

     $attributes_dropdown = '<select>'; 

     foreach ($product_attributes as $pa) { 
      $attributes_dropdown .= '<option value="' . $pa . '">' . $pa . '</option>'; 
     } 

     $attributes_dropdown .= '</select>'; 

     echo $attributes_dropdown; 
} 
+0

과 매우 유사합니다. 이것에, 그러나이 복잡한조차. 드롭 다운이 필요하지 않습니다. 제품을 설명하는 데 사용되는 브랜드 및 크기 카테고리를 추출하는 코드가 필요합니다. – Jim

관련 문제