Get WooCommerce product categories from WordPress

前端 未结 4 1080
甜味超标
甜味超标 2020-11-30 18:30

I am trying to get the product categories from WooCommerce through a function in my WordPress theme

    function get_me_list_of($atts, $content = null)
             


        
4条回答
  •  野性不改
    2020-11-30 18:57

    In my opinion this is the simplest solution

    $orderby = 'name';
                    $order = 'asc';
                    $hide_empty = false ;
                    $cat_args = array(
                        'orderby'    => $orderby,
                        'order'      => $order,
                        'hide_empty' => $hide_empty,
                    );
    
                    $product_categories = get_terms( 'product_cat', $cat_args );
    
                    if( !empty($product_categories) ){
                        echo '
    
                    
    
    
                    ';
                    }
    

提交回复
热议问题