4

I'm having a problem with WooCommerce / Wordpress templates. I used to have everything working.

I have this code in my functions.php file:

add_filter( 'template_include', 'wpse138858_woocommerce_category_archive_template' );
function wpse138858_woocommerce_category_archive_template( $original_template ) {
    if ( is_product_category() ) {
        return get_template_directory().'/woocommerce/archive-product.php';
    } else {
        return $original_template;
    }
}

This code chose my custom archive template for product categories and shop the main page. Suddenly, it's not working anymore. It seems like WordPress cannot use custom files from wp-content/themes/mytheme/woocommerce anymore. Single product page and product categories use page.php for some reason. I fixed an issue with single product page by creating file single-product.php on my theme folder. This works okay but I can't do the same with Woocommerce archive pages.

All archive pages uses page.php. They don't have pageId and I print out var_dump(is_product_category()); on some product category page, result is false.

Is there any way to force product categories to use archive-product.php template? How is it possible that category (archive) page uses page.php template?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
J Low
  • 41
  • 1
  • 2
  • Hey, Has this issue cropped up since the 3.3.0 update? I'm having the same issue and believe it is related to the FIX - Fix – Added woocommerce_output_product_categories to replace woocommerce_product_subcategories function to prevent outdated theme template files from outputting categories on the shop and category pages in err. – blackhill24 Feb 07 '18 at 14:47
  • @jlow did you ever figure this out?—i am having the same issue and spent a couple of hours the other night trying every possible solution i could find, but no matter what, for whatever reason, it just keeps defaulting back to the `page.php` template. i even double checked all of my conditionals to make sure they were executing with the correct values, and i am certain they are. – thesublimeobject Mar 31 '18 at 17:25

1 Answers1

3

Add add_theme_support( 'woocommerce' ); in your theme functions.php file. After this all WooCommerce templates will work as expected ( provided that the structure of the templates is correct ).

Samvel Aleqsanyan
  • 2,812
  • 4
  • 20
  • 28
Alex
  • 121
  • 1
  • 3