Allow template overrides for Shop page or any relating to (archive-product.php)

The `woocommerce_content();` is a catchall and requires the use of hooks for modifications to alter the Shop page or any relating to `archive-product.php` page eg Product Category, Taxonomy, Search pages. This change allows both. If you don't create an `archive-product.php` template override under the /woocommerce folder it will just use the `woocommerce_content();` catchall.
This commit is contained in:
Jason King 2017-06-28 19:48:52 +09:30 committed by GitHub
parent 8d68755338
commit 0b968fe9c3
1 changed files with 21 additions and 1 deletions

View File

@ -28,7 +28,27 @@ $sidebar_pos = get_theme_mod( 'understrap_sidebar_position' );
<main class="site-main" id="main">
<?php woocommerce_content(); ?>
<?php
$template_name = '\archive-product.php';
$args = array();
$template_path = '';
$default_path = untrailingslashit( plugin_dir_path(__FILE__) ) . '\woocommerce';
if ( is_singular( 'product' ) ) {
woocommerce_content();
//For ANY product archive, Product taxonomy, product search or /shop landing page etc Fetch the template override;
} elseif ( file_exists( $default_path . $template_name ) )
{
wc_get_template( $template_name, $args, $template_path, $default_path );
//If no archive-product.php template exists, default to catchall;
} else {
woocommerce_content( );
}
;?>
</main><!-- #main -->