Created
August 4, 2021 04:19
-
-
Save anhnn-mageplaza/da14a2d3629c6b9011ef7113e4f09982 to your computer and use it in GitHub Desktop.
This is the code for displaying WooCommerce Product Categories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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