0

Setup

I am running:

  • WordPress 5.4.1
  • WooCommerce 4.1.1

I am writing a custom theme that overrides some of the WooCommerce templates by placing my own templates in: themes/my_theme/woocommerce/template-name.php

I have established that the shop page (home) uses archive-product.php and have successfully copied the one from plugins/woocommerce/templates/archive-product.php to my theme and made some minor HTML changes which work fine. There are no functional changes in my theme's copy, just some HTML.

Problem

There is an option to set the shop page to show categories instead of products:

Appearance > Customize > WooCommerce > Catalogue

Shop page display is now set to Show Categories

However the shop homepage seems to ignore this setting entirely. It seems odd that WooCommerce's own template does not honour this setting!

How do I find this setting and then show the categories (as thumbnails) on the shop homepage?


As a side note, the Storefront theme does honour the setting but they do not have the template archive-product.php. Everything in Storefront is highly obfuscated and after much debugging of it / trying to take it apart I cannot discover which template file it is using for the shop page.

  • The template you're using is specifically made to showcase products, so I don't think it'll check that setting. Can you show a screenshot of the storefront theme page that does work with that setting? – Himad May 23 '20 at 0:39
  • I don’t have it to hand (as on mobile) but it literally replaces product thumbnails with category thumbnails. Why include a setting that doesn’t work with the templates that Woocommerce uses out of the box? Is Woocommerce making an assumption we’re using Storefront? – Ade May 23 '20 at 22:24
0

I found a workable solution. The WooCommerce default templates don't support the setting to show categories on the Shop page.

However using a shortcode with do_shortcode(), and a condition this can be achieved as follows:

if (is_shop()) {

  echo do_shortcode('[product_categories hide_empty="0"]');

} else {

  woocommerce_product_loop_start();

  if ( wc_get_loop_prop( 'total' ) ) {
    while ( have_posts() ) {
      the_post();

      /**
      * Hook: woocommerce_shop_loop.
      */
      do_action( 'woocommerce_shop_loop' );

      wc_get_template_part( 'content', 'product' );
    }

  }

  woocommerce_product_loop_end();
}

Still:

  • I would like to know how to pick up the 'show categories' customisation setting shown in the question, so my theme responds to that.
  • Is there a better way than using do_shortcode(), this feels like a bit of a hack

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.