Sage 9 + WooCommerce: Different templates for Single Product

Hello everyone,

Trying out Sage for the first time with WooCommerce, running the latest versions of both and using the recommended roots/sage-woocommerce package for this integration.

What I can’t for the life of me figure out is how to achieve multiple product templates. Let’s say there is a regular product and a “subscription” product, and these two require different treatments. You’d think that just changing the filename to the more granular structure based on Wordpress template hierarchy would do the trick — using a category name as a suffix to drill down further:

-- single-product.blade.php
-- content-single-product.blade.php
-- content-single-product-{category}.blade.php

This doesn’t seem to work. Otherwise editing the “single-product.blade.php” file to contain some sort of a conditional based on category name:

  global $post;
  $terms = wp_get_post_terms( $post->ID, 'product_cat' );
  foreach ( $terms as $term ) $categories[] = $term->slug;
  if ( in_array( 'subscriptions', $categories ) ) {
    wc_get_template_part( 'content', 'single-product-subscriptions' );
  } else {
    wc_get_template_part( 'content', 'single-product' );

The condition fires correctly but the wc_get_template_part produces a blank template.

So what is the proper way to do this? Sure I am just missing something simple here to be able to differentiate single product templates.

Thanks for your help in advance!

This topic was automatically closed after 42 days. New replies are no longer allowed.