在升级到Woocommerce版本3.1.1之前,我已经使用了下面的代码很多年了,没有任何问题。
该函数只需将默认的存档-Product.php更改为基于定义的Woocommerce类别段塞的替代模板。
我已经阅读过变更日志,我认为有几件事情可能与我的问题有关,但我不确定,因此我为什么要在这里联系:)
在我看来,“变革”杂志的有关说明似乎是:
修正-添加woocommerce_output_product_categories,以取代woocommerce_product_subcategories功能,以防止过时的主题模板文件输出类别上的商店和类别页的错误。
然而,在以前的3.3.0版本中,对Woocommerce的默认布局/主题做了许多更改,这也可能是错误的。
在这个问题上的任何帮助或指导都是很棒的。
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';
}
else
{
return $original_template;
}
}编辑-函数中有错误不应该出现,对不起.我已经直接从现场复制了代码,并将这个类别减少了,这样它就更容易读了。
发布于 2018-02-18 23:25:24
安装插件WP回滚,然后单击woocommerce上的Install菜单中的回滚。不得不做同样的事。
发布于 2018-02-08 12:32:00
else语句在elseif语句中。你必须像这样把它放在后面:
add_filter( 'template_include', 'wpse138858_woocommerce_category_archive_template' );
function wpse138858_woocommerce_category_archive_template( $original_template ) {
// If cat 1,2,3 return template archive product set 1
if(is_product_category(array('cat-1','cat-2','cat-3'))) {
return get_stylesheet_directory().'/woocommerce/archive-product_set_1.php';
// If cat 4,5,6 return template archive product set 2
}elseif(is_product_category(array('cat-4','cat-5','cat-6'))) {
return get_stylesheet_directory().'/woocommerce/archive-product_set_2.php';
// Else return original template
}else {
return $original_template;
}
}https://stackoverflow.com/questions/48684218
复制相似问题