How do I display a “category products drop down in a wordpress page” in Woocommerce 2.5.2

前端 未结 3 514
北海茫月
北海茫月 2021-01-28 09:08

I would like to display a drop down menu for products in a category.

 
         


        
3条回答
  •  孤街浪徒
    2021-01-28 09:42

    You can also use the function wp_dropdown_categories to make your code simpler. To get a dropdown of categories of products you can write like this.

    $args = array('hide_empty'=> 0,
      'taxonomy'=> 'product_cat',
      'hierarchical'=>1);
    
    wp_dropdown_categories($args);
    

    Or if you want to hold the output in a variable you can use the argument 'echo'=>0 and then echo the variable to get the same output.

    $args = array('hide_empty'=> 0,
        'taxonomy'=> 'product_cat',
        'hierarchical'=>1,
        'echo'=>0);
    
    $cats = wp_dropdown_categories($args);
    echo $cats;
    

提交回复
热议问题