How to show WooCommerce Categories on ‘shop’ page instead of products?

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