2018-02-08 11:17
浏览 55

更新3.3.0 / 3.3.1后,Woocommerce archive-product.php模板功能中断

I've been using the code below for a number of years with no problems what so ever until I upgraded to Woocommerce version 3.1.1.

The function simply changes the default archive-product.php to an alternative template based on the defined Woocommerce category slug.

I've read through the change logs and there are a few things I think that may be connected to my problem but I'm not sure, hence why I'm reaching out here :)

The relevant note from the changelog to me seemed to be:

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.

However, there were many changes made to the default layout/theme of Woocommerce in the previous version 3.3.0 which may also be at fault.

Any help or guidance on this one would be awesome.

add_filter( 'template_include', 'wpse138858_woocommerce_category_archive_template' );

function wpse138858_woocommerce_category_archive_template( $original_template ) {

    if ( is_product_category( array( 'cat-1', 'cat-2' ) ) )
        return get_stylesheet_directory().'/woocommerce/archive-product_no_sidebar.php';
    elseif ( is_product_category( array( 'cat-3', 'cat-4' ) ) )
        return get_stylesheet_directory().'/woocommerce/archive-product_sidebar.php';
    elseif ( is_product_category( array( 'cat-5', 'cat-6' ) ) )
        return get_stylesheet_directory().'/woocommerce/archive-product_clubs_page.php';
        return $original_template;

EDIT - There were errors in the function that shouldn't have been there, my fault, sorry... I have copied the code straight from the live site and just cut the category down so its more readable

图片转代码服务由CSDN问答提供 功能建议

我一直在使用下面的代码多年没有任何问题,直到我升级到Woocommerce 版本3.1.1。




修复 - 添加了woocommerce_output_product_categories来替换 woocommerce_product_subcategories函数,以防止过时的主题 模板文件输出类别 在错误的商店和类别 页面

然而,在之前版本3.3.0中对Woocommerce的默认布局/主题进行了许多更改 也可能有问题。

任何帮助 或者对这个的指导会很棒。

功能wpse138858_woocommerce_category_archive_template($ original_template){
 if(is_product_category(array('cat-1')  ,'cat-2')))
返回get_stylesheet_directory()。'/ woocommerce / archive-product_no_sidebar.php'; 
 elseif(is_product_category(array('cat-3','cat-  4')))
返回get_stylesheet_directory()。'/ woocommerce / archive-product_sidebar.php'; 
 elseif(is_product_category(array('cat-5','cat-6'))  )
 return get_stylesheet_directory()。'/ woocommerce / archive-product_clubs_page.php'; 
 return $ original_template; 
  <  / pre> 

编辑 - 函数中存在错误,不应该存在,我的错,抱歉...我复制了 代码直接来自实时网站,只是减少了类别,使其更具可读性

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题