Skip to content

Instantly share code, notes, and snippets.

@huzaifaarain
Created December 6, 2018 12:49
Show Gist options
  • Save huzaifaarain/70f33f0ee6b3723987fa116743c9d097 to your computer and use it in GitHub Desktop.
Save huzaifaarain/70f33f0ee6b3723987fa116743c9d097 to your computer and use it in GitHub Desktop.
Get list of all product categories in WooCommerce
$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 '
 
<ul>';
    foreach ($product_categories as $key => $category) {
        echo '
 
<li>';
        echo '<a href="'.get_term_link($category).'" >';
        echo $category->name;
        echo '</a>';
        echo '</li>';
    }
    echo '</ul>
 
 
';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment