我正在尝试仅为woocommerce商店中的一个产品使用自定义页面。我一直在尝试应用附加功能但没有成功(哪些代码来自this answer)。
我在/ woocommerce文件夹中创建了一个single-product.php文件的副本,其中添加了一些代码,但单个产品视图只显示“标准”单一产品-php而不是我的单产品-mock.php文件。
该产品确实具有“定制”的产品类别。
add_filter( 'template_include', 'so_43621049_template_include', 10 );
function so_43621049_template_include( $template ) {
if ( is_singular('product') && (has_term( 'custom', 'product_cat')) ) {
$template = get_stylesheet_directory() . '/woocommerce/single-product-mock.php';
}
retur
你正在使用的The code工作得非常完美。你的代码也有点不完整:
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-mock.php';
}
return $template;
}
所以问题可能与:
解决方案:
single-product-mock.php
(但不在“模板”子文件夹中)single-product.php
模板复制到活动子主题(或活动主题)中的“woocommerce”文件夹中
进入后端Woocommerce>状态...您通常会在“模板”部分(在本页末尾)看到:
积极的儿童主题:
活跃的主题:
如果未启用,则应搜索并查看相关的Woocommerce文档。其中之一,应该解决你的问题。