下拉列表中的所有Woocommerce类别

时间:2014-10-16 09:17:32

标签: php wordpress woocommerce

我已经为此工作了一天,我非常紧张,你能帮助我在下拉菜单中检索所有类别的woocommerce吗?在这里,我想在下拉菜单中检索

    $options[] = array(  
     "name" => "Featured section category",
        "desc" => "Select the category that you would like to have displayed in Featured list on your homepage.",
        "id" => $shortname."_story_category",
        "std" => "Uncategorized",
        "type" => "select",
        "options" => $woo_category);

如何在此var $ woo_category中显示所有类别,我使用此代码,但其显示wordpress类别不是woocommerce

$woo_categories = array();
$woo_categories_obj = get_categories( 'hide_empty=0' );
foreach ($woo_categories_obj as $woo_cat) {
$woo_categories[$woo_cat->cat_ID] = $woo_cat->cat_name;}
$categories_tmp = array_unshift($woo_categories, "Select a category:" );

帮我完成这个简单的任务,

2 个答案:

答案 0 :(得分:1)

这个简单的查询可以获得所有的woocommerce类别..

$args = array( 'type' => 'product', 'taxonomy' => 'product_cat' ); 
$categories = get_categories( $args ); 

用于显示..

<?php foreach ($categories as $cat) { ?>
        <li><a href="<?php echo get_term_link($cat->slug, 'product_cat') ?>"><i class="fa fa-chevron-right"></i><?php echo $cat->name; ?></a></li>
<?php } ?>

希望它可以帮到你。

答案 1 :(得分:0)

您需要通过分类法

$args=array(           
                'hide_empty' => 0,
                'taxonomy' => 'product_cat'
            );
$woo_categories_obj = get_categories($args);