Skip to content

Instantly share code, notes, and snippets.

@Korveld
Last active September 9, 2020 10:10
Show Gist options
  • Select an option

  • Save Korveld/61cfacf4bc62a776b3b80746f7c6bebf to your computer and use it in GitHub Desktop.

Select an option

Save Korveld/61cfacf4bc62a776b3b80746f7c6bebf to your computer and use it in GitHub Desktop.
Get list of woocommerce categories
<?php
$cat_args = array(
'orderby' => 'name',
'order' => 'asc',
'hide_empty' => false,
// 'include' => 177 // (array|string) Array or comma/space-separated string of term ids to include. Default empty array.
);
$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