gpt4 book ai didi

woocommerce - 显示 woocommerce 类别列表

转载 作者:行者123 更新时间:2023-12-05 03:10:10 28 4
gpt4 key购买 nike

如何获取 woocommerce 中的类别列表?使用这段代码,我得到了 wordpress 类别列表:

function gaga_lite_category_lists(){
$categories = get_categories(
array(
'hide_empty' => 0,
'exclude' => 1
)
);


$category_lists = array();
$category_lists[0] = __('Select Category', 'gaga-lite');
foreach($categories as $category) :
$category_lists[$category->term_id] = $category->name;
endforeach;
return $category_lists;

}

我想用 woocommerce 类别替换它。

最佳答案

WooCommerce Product Category are treated as product_cat taxonomy

这是代码。

function gaga_lite_category_lists()
{
$category_lists = array();
$category_lists[0] = __('Select Category', 'gaga-lite');
$args = array(
'taxonomy' => 'product_cat',
'orderby' => 'name',
'hierarchical' => 0, // 1 for yes, 0 for no
'hide_empty' => 0,
'exclude' => 1 //list of product_cat id that you want to exclude (string/array).
);
$all_categories = get_categories($args);
foreach ($all_categories as $cat)
{
if ($cat->category_parent == 0)
{
$category_lists[$cat->term_id] = $cat->name;
//get_term_link($cat->slug, 'product_cat')
}
}
return $category_lists;
}

关于woocommerce - 显示 woocommerce 类别列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40881821/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com