Skip to content

Instantly share code, notes, and snippets.

@mattradford
Last active September 20, 2021 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mattradford/c1620aee502e0955416883ba48c1d1e0 to your computer and use it in GitHub Desktop.
Save mattradford/c1620aee502e0955416883ba48c1d1e0 to your computer and use it in GitHub Desktop.
WooCommerce Product category (showing products) different template
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' );
@mattradford
Copy link
Author

Assumes archive pages showing products have no term children, which I think is pretty accurate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment