Åsm*_*gda 3 php wordpress templates custom-taxonomy woocommerce
我正在尝试对woocommerce商店中的仅一种产品使用自定义页面。我一直在尝试应用附加功能,但没有成功(该代码来自此答案)。
我在/ woocommerce文件夹中创建了single-product.php文件的副本,并添加了一些代码,但是单一产品视图仅显示“标准”单一产品php,而不显示我的single-product-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
Run Code Online (Sandbox Code Playgroud)
您正在使用的代码非常完美。您的代码也有点不完整:
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;
}
Run Code Online (Sandbox Code Playgroud)
因此,问题可能与以下方面有关:
解决方案:
single-product-mock.php其中之一,应该解决您的问题。