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
is_shop()
function to check whether current page is shop page or not. – Rohil_PHPBeginner