将 Woocommerce 评论评论模板替换为默认评论模板?

nah*_*hum 2 comments review woocommerce

如何删除 woocommerce 用于评论的评论模板,而是默认使用网站评论模板?

我编辑了 single-product-reviews.php 以使其适应网站的评论模板,并使用 woocommerce_product_review_comment_form_args 来适应表单,但只是想为什么不直接使用我已有的自定义评论模板。

编辑:已经达到了成功的方法,但不认为这是最好的

add_action('init', 'mdlr_disable_reviews');
function mdlr_disable_reviews() {
remove_filter( 'comments_template', array( WC_Template_Loader::init(),'comments_template_loader' ) );
add_filter( 'comments_template', array( WC_Template_Loader::init(),'mdlr_new_product_comments' )); //need this?
}
Run Code Online (Sandbox Code Playgroud)

//然后禁用选项卡下的评论/评论

add_filter( 'woocommerce_product_tabs', 'mdlr_remove_reviews_tab');
function mdlr_remove_reviews_tab( $tabs ) {
unset( $tabs[ 'reviews' ] );
 return $tabs;
}
Run Code Online (Sandbox Code Playgroud)

//然后我移动了评论/评论

 add_action( 'woocommerce_after_single_product_summary','mdlr_new_product_comments');
 function mdlr_new_product_comments() {
 if ( ! comments_open() ) {
 return;
 }
 comments_template();
 }
Run Code Online (Sandbox Code Playgroud)

小智 5

只需添加具有更高优先级的过滤器,如下所示:

add_filter( 'comments_template', function() { return '/comments.php'; }, 30 );
Run Code Online (Sandbox Code Playgroud)