[英]Using a custom single product template for a specific product category in 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
您正在使用的代碼非常完美。 您的代碼也有點不完整:
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
其中之一,應該解決您的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.