2016-08-13 241 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

相关问题