Skip to content

Instantly share code, notes, and snippets.

@anhnn-mageplaza
Created August 4, 2021 04:19
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 anhnn-mageplaza/da14a2d3629c6b9011ef7113e4f09982 to your computer and use it in GitHub Desktop.
Save anhnn-mageplaza/da14a2d3629c6b9011ef7113e4f09982 to your computer and use it in GitHub Desktop.
This is the code for displaying WooCommerce Product Categories
function woocommerce_product_category( $args = array() ) {
$woocommerce_category_id = get_queried_object_id();
$args = array(
'parent' => $woocommerce_category_id
);
$terms = get_terms( 'product_cat', $args );
if ( $terms ) {
echo '<ul class="woocommerce-categories">';
foreach ( $terms as $term ) {
echo '<li class="woocommerce-product-category-page">';
woocommerce_subcategory_thumbnail( $term );
echo '<h2>';
echo '<a href="' . esc_url( get_term_link( $term ) ) . '" class="' . $term->slug . '">';
echo $term->name;
echo '</a>';
echo '</h2>';
echo '</li>';
}
echo '</ul>';
}
}
add_action( 'woocommerce_before_shop_loop', 'woocommerce_product_category', 100 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment