Last active
September 20, 2021 12:56
-
-
Save mattradford/c1620aee502e0955416883ba48c1d1e0 to your computer and use it in GitHub Desktop.
WooCommerce Product category (showing products) different template
This file contains hidden or 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 tend_product_listing( $original_template ) { | |
if ( is_tax( 'product_cat' ) ) { | |
$term = get_queried_object(); | |
$children = get_terms( $term->taxonomy, array( | |
'parent' => $term->term_id, | |
'hide_empty' => false, | |
) ); | |
if ( ! $children ) { | |
return wc_get_template_part( 'archive-product-listing' ); | |
} else { | |
return $original_template; | |
} | |
return $original_template; | |
} | |
} | |
add_filter( 'template_include', 'tend_product_listing' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assumes archive pages showing products have no term children, which I think is pretty accurate.