Created
November 28, 2019 11:02
-
-
Save slaffko1/43151a68d637383101955905e5999a41 to your computer and use it in GitHub Desktop.
Woocommerce categories before products
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