Sage WooCommerce Custom Templates

Hi there,
I am using Sage with WooCommerce and sage-woocommerce library for my theme.

I was able to create custom templates for product custom taxonomy archive referring to this topic

But now I am struggling to find a way to have different template based on taxonomies for the content-product.blade.php

Example:
content-product.blade.php is different from content-product-{custom-taxonomy}-{term}.blade.php

The function wc_get_template_part(‘content’, ‘product-custom-taxonomy-term’) it doesn’t seem to work.

All I want to do is to have 2 different layouts based on the custom taxonomy term without using body class or multiple conditionals checking the queries inside the templates.

Anyone who can help with this?

Thanks in advance :slight_smile:

Hi @strarsis, thanks for your quick reply.

I am sorry, I didn’t find any solutions in your link.
As I said the problem is not for the archive loop template (the archive.blade.php according with sage-woocommerce) but for content-product.blade.php that is the file that shows the “single” product inside the archive loop.

For the archive.blade.php I already found a solutions that I posted earlier.

So you want to have a different content-product template, depending on what taxonomies that product belongs to.

You can override the wc_get_template_part filter (same name as the method using it) and conditionally use a different template file than the default one:


You would have to adjust the logic in the linked sample code, in this case by checking for the specific taxonomy or taxonomies and picking a matching template file (or for a combination of assigned taxonomies, etc.).
1 Like

That could be a solution.

Actually I found a workaround using wc_get_template('content-{term}.blade.php', [], 'woocommerce')
instead of using wc_get_template_part

Do you think is better to use the standard methods woocommerce is using for this job?

Sure! I always prefer the core functionality over adding custom code.

1 Like

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