Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woogists/0e4e531313c9096637651e355e8f895d to your computer and use it in GitHub Desktop.
Save woogists/0e4e531313c9096637651e355e8f895d to your computer and use it in GitHub Desktop.
Top-level Product Category List Shortcode
<?php
/*
* The shortcode is [top_level_product_categories_list]
*/
add_shortcode('top_level_product_categories_list', 'wc_shortcode_top_level_product_categories_list');
function wc_shortcode_top_level_product_categories_list() {
ob_start();
$args = array(
'taxonomy' => 'product_cat',
'parent' => 0
);
$product_categories = get_categories($args);
echo '<ul>';
foreach ($product_categories as $category) {
echo '<li><a href="' . get_term_link($category->slug, 'product_cat') . '">' . $category->name . '</a></li>';
}
echo '</ul>';
return ob_get_clean();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment