【发布时间】:2018-08-12 03:07:05
【问题描述】:
我正在尝试仅为一种 ID 为 5555 的产品制作单独的模板。从其页面中删除照片并更改块结构。覆盖此文件会影响所有产品页面。
wp-content\plugins\woocommerce\templates\content-single-product.php
逻辑解决方案是添加一个条件:如果产品单个产品页面的 ID 为 5555,则为其页面使用另一个模板。 我试过这个选项,但它不起作用。
/**
* Custom single product template.
*/
add_filter( 'single_template', 'get_custom_post_type_template' );
function get_custom_post_type_template($single_template) {
global $post;
if ($post->post_type == 'product') {
$single_template = dirname( __FILE__ ) . '/single-template.php';
}
return $single_template;
}
add_filter( 'template_include', 'portfolio_page_template', 99 );
function portfolio_page_template( $template ) {
if ( is_page( 'slug' ) ) {
$new_template = locate_template( array( 'single-template.php' ) );
if ( '' != $new_template ) {
return $new_template ;
}
}
return $template;
}
或选项 2:删除此挂钩:
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
仅来自一个特定的产品页面:
【问题讨论】:
标签: php wordpress templates woocommerce product