0
使用WP和WooCommerce產品類別。我試圖在下拉菜單中顯示所有產品類別。我有這個工作,但是我需要層次結構也被顯示。例如,蘋果是水果的一個子類別。在下拉菜單中顯示所有產品類別
所以我想顯示器看起來像這樣:
Fruit
-Apple
-Pear
但目前看起來是這樣的:
Fruit
Apple
Pear
我的代碼目前看起來是這樣的:
$args = array(
'number' => $number,
'orderby' => $orderby,
//'name' => 'select_name',
//'id' => 'select_name',
'order' => $order,
'hide_empty' => false,
'include' => $ids,
'hierarchical' => true
);
$product_categories = get_terms('product_cat', $args);
我標記:
<select name='categorylist'>
<?php foreach($product_categories as $cat) {
echo "<option value='{$cat->name}'>{$cat->name}</option>";
} ?>
我知道可以像這樣設置子類別的層次結構。任何人都可以建議我可以做我的$ args數組來實現這一點。由於
你只需要檢查,如果一個特定的'$ product_categories'元素有有'「分層」 == TRUE'值。我假設你可以查詢這個。 – Defiant
我在這裏拉回了幾百個類別,所以需要在飛行中設置。謝謝 –