2016-08-13 8 views
0

ブランド、色、サイズなどの親カテゴリー別に組織された商品を持っているWoocommerceショップで働いています。Woocommerce製品の特定の商品の子供のカテゴリタイトルを親に基づいて表示

クライアントは、各製品のサムネイルの下に各製品のブランドとサイズ(靴は製品です)をグリッド/ループビューに表示したいと考えています(例:Colorのサブカテゴリには、赤、青、ピンクなどがあります)。フロントページとアーカイブページ。

各製品は1つのブランドですが、複数のサイズが用意されている可能性があります。

だから、基本的に、私はそうのように、単一の製品のためにのみ、特定のサブカテゴリのタイトルを表示する方法があるかどうかを知る必要があります。

[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

関連する問題