【发布时间】:2018-06-17 23:12:20
【问题描述】:
以下链接中提供的解决方案不再有效:
Using a custom single product template for a specific product category in Woocommerce
我已经完成了 LOIC 预想的诊断步骤。
我将 single-product.php 文件的副本添加到我的子主题的 woocommerce 文件夹中。
当我检查 Woo 状态页面时,它确认该页面正在覆盖 woo 模板。
我创建了一个新产品并为其分配了类别:自定义(带有 slug:自定义)。
我将以下代码放在我的functions.php中:
add_filter( 'template_include', 'custom_single_product_template_include', 50, 1 );
function custom_single_product_template_include( $template ) {
if ( is_singular('product') && (has_term( 'custom', 'product_cat')) ) {
$template = get_stylesheet_directory() . '/woocommerce/single-product-custom.php';
}
return $template;
}
我从 single-product.php 的副本中删除了钩子并将其重命名为:single-product-custom.php 并将其放在我的子主题的 woocommerce 文件夹中。
清除所有网站缓存和我的浏览器历史记录。
但是,测试产品仍然显示默认的单品页面。
我哪里出错了,我该去哪里?
【问题讨论】:
-
你能先只测试一个条件吗? if ( is_singular('product') ) {
-
嘿。是的,检查问题仍然存在。可以肯定的是,我在子主题的 woocommerce 文件夹中的文件应该是 woo single-product.php 模板的副本(自定义版本),而不是 content-single-product.php 模板的副本。对吗?
标签: woocommerce