I am new to WooCommerce and I am trying to build a shop using my custom theme created from scratch. The home page is a static page (custom template) just giving details about the shop . 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 basic shop page. I want it to show the categories and subcategories of the products and some featured products with no prices and add to cart stuff. Which way do you suggest? I thought of something which currently works but I don't know if it will cause any issues later. I edited the archive-product.php like this:
<?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 check if the url ends to '/shop/'...So the code of archive-product.php is used according to url. Is this ok or not? Is there any other safer way to achieve this? Any help would be appreciated. Thanks
Take a look at the taxonomy-product_cat.php
and taxonomy-product_tag.php
templates and you will see that they both call the archive-product.php
template.
wc_get_template( 'archive-product.php' );
Therefore, if you wish to change the shop archive, but not the taxonomy archives you need to duplicate the archive-product.php
to another file... say: archive-product-alt.php
and change the taxonomy templates to call this file instead.
wc_get_template( 'archive-product-alt.php' );
Or, alternatively, you could just copy the contents of archive-product.php
into taxonomy-product_cat.php
.