WooCommerce - change the store page layout but keep the archive-product.php file

I am new to WooCommerce and I am trying to create a store using my own theme, built from scratch. The home page is a static page (custom template) by simply providing store details. I created a folder in my themes folder named woocommerce and copied the template files. So, I want to keep the archive-product.php, but I need to change the layout of the main store page. I want it to show product categories and subcategories and some popular products without any prices and add things to cart. How do you suggest? I was thinking of something that is currently working, but I don't know if this will cause any problems later. I edited the archive-product.php file as follows:

<?php 
$shop_url = "$_SERVER[REQUEST_URI]";
$shop_end = "/shop/";
function endsWith($haystack, $needle) {
    $length = strlen($needle);
    if ($length == 0) {
        return true;
    }
    return (substr($haystack, -$length) === $needle);
}
if (!endsWith($shop_url, $shop_end)) { 
?> 
    archive-product.php stuff 
<?php } else { ?>
    custom shop basic page stuff
<?php } ?>

      

I am checking if the url ends with '/ shop /' .... The archive-product.php code is used according to the url. Is this normal or not? Is there an even safer way to achieve this? Any help would be greatly appreciated. Thanks to

+3


source to share


1 answer


Take a look at taxonomy-product_cat.php

and taxonomy-product_tag.php

, and you can see that they both call the template archive-product.php

.

wc_get_template( 'archive-product.php' );

      

Therefore, if you want to change the store archive, but not the taxonomic archives, you need to duplicate archive-product.php

to another file ... say: archive-product-alt.php

and change the taxonomy templates to invoke that file instead.



wc_get_template( 'archive-product-alt.php' );

      

Or, alternatively, you can just copy the content archive-product.php

to taxonomy-product_cat.php

.

+1


source







All Articles